ZQuest Classic Coverage Report


Directory: src/
File: src/zq/zq_class.cpp
Date: 2025-11-21 07:35:34
Exec Total Coverage
Lines: 3099 8734 35.5%
Functions: 83 312 26.6%
Branches: 2702 7719 35.0%

Line Branch Exec Source
1 #include <chrono>
2 #include <cstring>
3 #include <exception>
4 #include <string>
5 #include <stdexcept>
6 #include <map>
7
8 #include "base/general.h"
9 #include "base/pal_tables.h"
10 #include "base/version.h"
11 #include "base/zapp.h"
12 #include "base/zdefs.h"
13 #include "dialog/info.h"
14 #include "metadata/metadata.h"
15
16 #include "base/qrs.h"
17 #include "base/dmap.h"
18 #include "base/packfile.h"
19 #include "base/cpool.h"
20 #include "base/autocombo.h"
21 #include "base/gui.h"
22 #include "base/msgstr.h"
23 #include "zc/zelda.h"
24 #include "zq/zq_class.h"
25 #include "zq/render.h"
26 #include "zq/render_map_view.h"
27 #include "zq/zq_misc.h"
28 #include "zq/zquest.h"
29 #include "base/qst.h"
30 #include "base/colors.h"
31 #include "tiles.h"
32 #include "base/zsys.h"
33 #include "sprite.h"
34 #include "items.h"
35 #include "zc/zc_sys.h"
36 #include "base/md5.h"
37 #include "hero_tiles.h"
38 #include "subscr.h"
39 #include "zq/zq_strings.h"
40 #include "zq/zq_subscr.h"
41 #include "zc/ffscript.h"
42 #include "base/util.h"
43 #include "zq/zq_files.h"
44 #include "dialog/alert.h"
45 #include "slopes.h"
46 #include "drawing.h"
47 #include "zinfo.h"
48 #include "zq/render_minimap.h"
49 #include "base/mapscr.h"
50 #include "iter.h"
51 #include <fmt/format.h>
52 #include <filesystem>
53
54 #ifdef __EMSCRIPTEN__
55 #include "base/emscripten_utils.h"
56 #endif
57
58 namespace fs = std::filesystem;
59
60 using namespace util;
61
62 extern uint8_t ViewLayer3BG, ViewLayer2BG;
63 extern int32_t LayerDitherBG, LayerDitherSz;
64 extern bool NoHighlightLayer0;
65
66 using std::string;
67 using std::pair;
68
69 #define COLOR_SOLID vc(4)
70 #define COLOR_SLOPE vc(13)
71 #define COLOR_LADDER vc(6)
72 //#define COLOR_EFFECT vc(10)
73
74 //const char zqsheader[30]="ZQuest Classic String Table\n\x01";
75 extern char msgbuf[MSG_NEW_SIZE*8];
76
77 extern string zScript;
78
79 12 zmap Map;
80 int32_t prv_mode=0;
81
82 bool save_warn=true;
83
84 int32_t COMBOPOS(int32_t x, int32_t y)
85 {
86 return (((y) & 0xF0) + ((x) >> 4));
87 }
88 int32_t COMBOPOS_B(int32_t x, int32_t y)
89 {
90 if(unsigned(x) >= 256 || unsigned(y) >= 176)
91 return -1;
92 return COMBOPOS(x,y);
93 }
94 int32_t COMBOX(int32_t pos)
95 {
96 return ((pos) % 16 * 16);
97 }
98 int32_t COMBOY(int32_t pos)
99 {
100 return ((pos) & 0xF0);
101 }
102
103 void reset_dmap(int32_t index)
104 {
105 bound(index,0,MAXDMAPS-1);
106 DMaps[index].clear();
107 DMaps[index].title = "";
108 sprintf(DMaps[index].intro, " ");
109 }
110
111 void reset_dmaps()
112 {
113 for(int32_t i=0; i<MAXDMAPS; i++)
114 reset_dmap(i);
115 }
116
117 void truncate_dmap_title(std::string& title)
118 {
119 title.resize(21, ' ');
120 }
121
122 mapscr* zmap::get_prvscr()
123 {
124 return &prvscr;
125 }
126
127
7/12
✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 23 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 138 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 115 times.
✓ Branch 7 taken 23 times.
✓ Branch 8 taken 23 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 23 times.
✗ Branch 11 not taken.
138 zmap::zmap()
128 {
129 23 can_paste=false;
130 23 prv_cmbcycle=0;
131 23 prv_advance=0;
132 23 prv_freeze=0;
133 23 copyffc=-1;
134
135 23 memset(scrpos, 0, sizeof(scrpos));
136 23 memset(scrview, 0, sizeof(scrview));
137 23 screens=NULL;
138 23 prv_time=0;
139 23 prv_scr=0;
140 23 prv_map=0;
141 23 copyscr=0;
142 23 cursor={};
143 copymap=0;
144 layer_target_map = 0;
145 layer_target_scr = 0;
146 layer_target_multiple = 0;
147 }
148
149 11 void zmap::clear()
150 {
151
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 *this = zmap();
152 11 }
153 void zmap::force_refr_pointer()
154 {
155 if(unsigned(cursor.map) > map_count || (cursor.map*MAPSCRS > TheMaps.size()))
156 screens = nullptr;
157 else screens = &TheMaps[cursor.map*MAPSCRS];
158 }
159 bool zmap::CanUndo()
160 {
161 return input_undo_stack.size() > 0;
162 }
163 bool zmap::CanRedo()
164 {
165 return input_redo_stack.size() > 0;
166 }
167 bool zmap::CanPaste()
168 {
169 return can_paste;
170 }
171 int32_t zmap::CopyScr()
172 {
173 return (copymap<<8)+copyscr;
174 }
175 int32_t zmap::getCopyFFC()
176 {
177 return copyffc;
178 }
179 set_ffc_command::data_t zmap::getCopyFFCData()
180 {
181 return set_ffc_command::create_data(copymapscr.ffcs[copyffc]);
182 }
183 67 int32_t zmap::getMapCount()
184 {
185 67 return map_count;
186 }
187 int32_t zmap::getLayerTargetMap()
188 {
189 return layer_target_map;
190 }
191 int32_t zmap::getLayerTargetScr()
192 {
193 return layer_target_scr;
194 }
195 int32_t zmap::getLayerTargetMultiple()
196 {
197 return layer_target_multiple;
198 }
199 bool zmap::isDungeon(int32_t scr)
200 {
201 for(int32_t i=0; i<4; i++)
202 {
203 if(screens[scr].data[i]!=screens[TEMPLATE].data[i])
204 {
205 return false;
206 }
207 }
208
209 return true;
210 }
211
212 bool zmap::clearall(bool validate)
213 {
214 Color=0;
215 char tbuf[10];
216
217 if((header.templatepath[0]!=0)&&validate)
218 {
219 if(!valid_zqt(header.templatepath))
220 {
221 jwin_alert("Error","Invalid Quest Template",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
222 return false;
223 }
224 }
225
226 for(int32_t i=0; i<map_count; i++)
227 {
228 setCurrMap(i);
229 sprintf(tbuf, "%d", i);
230 clearmap(true);
231 }
232
233 setCurrMap(0);
234 return true;
235 }
236
237 bool zmap::reset_templates(bool validate)
238 {
239 //why are we doing this?
240 if(colordata==NULL)
241 {
242 return false;
243 }
244
245 //int32_t ret;
246 word version, build, dummy, sversion=0;
247 byte dummyc;
248 word dummyw;
249 //int32_t section_size;
250 word temp_map_count;
251 mapscr temp_mapscr;
252 PACKFILE *f=NULL;
253
254 // setPackfilePassword(datapwd);
255 f=open_quest_template(&header, "modules/classic/default.qst", validate);
256 get_version_and_build(f, &version, &build);
257
258 if(!find_section(f, ID_MAPS))
259 {
260 // setPackfilePassword(NULL);
261 return false;
262 }
263
264 //section version info
265 if(!p_igetw(&sversion,f))
266 {
267 return false;
268 }
269
270 if(!p_igetw(&dummy,f))
271 {
272 return false;
273 }
274
275 //section size
276 dword dummy_size;
277 if(!p_igetl(&dummy_size,f))
278 {
279 return false;
280 }
281
282 //finally... section data
283 if(!p_igetw(&temp_map_count,f))
284 {
285 return false;
286 }
287
288 if(version>12)
289 {
290 if(!p_getc(&dummyc,f))
291 return qe_invalid;
292
293 if(!p_getc(&dummyc,f))
294 return qe_invalid;
295
296 if(!p_igetw(&dummyw,f))
297 return qe_invalid;
298
299 if(!p_igetw(&dummyw,f))
300 return qe_invalid;
301
302 if(!p_igetw(&dummyw,f))
303 return qe_invalid;
304
305 if(!p_igetw(&dummyw,f))
306 return qe_invalid;
307
308 if(!p_igetw(&dummyw,f))
309 return qe_invalid;
310
311 if(!p_igetw(&dummyw,f))
312 return qe_invalid;
313
314 if(!p_igetw(&dummyw,f))
315 return qe_invalid;
316
317 if(!p_igetw(&dummyw,f))
318 return qe_invalid;
319
320 if(!p_igetw(&dummyw,f))
321 return qe_invalid;
322
323 if(!p_igetw(&dummyw,f))
324 return qe_invalid;
325
326 if(!p_getc(&dummyc,f))
327 return qe_invalid;
328
329 if(!p_getc(&dummyc,f))
330 return qe_invalid;
331 }
332
333 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
334 {
335 readmapscreen(f, &header, &temp_mapscr, sversion);
336 }
337
338 readmapscreen(f, &header, &TheMaps[128], sversion);
339 readmapscreen(f, &header, &TheMaps[129], sversion);
340
341 for(int32_t i=0; i<(MAPSCRS-(MAPSCRSNORMAL+2)); ++i)
342 {
343 readmapscreen(f, &header, &temp_mapscr, sversion);
344 }
345
346 if(version>12)
347 {
348 if(!p_getc(&dummyc,f))
349 return qe_invalid;
350
351 if(!p_getc(&dummyc,f))
352 return qe_invalid;
353
354 if(!p_igetw(&dummyw,f))
355 return qe_invalid;
356
357 if(!p_igetw(&dummyw,f))
358 return qe_invalid;
359
360 if(!p_igetw(&dummyw,f))
361 return qe_invalid;
362
363 if(!p_igetw(&dummyw,f))
364 return qe_invalid;
365
366 if(!p_igetw(&dummyw,f))
367 return qe_invalid;
368
369 if(!p_igetw(&dummyw,f))
370 return qe_invalid;
371
372 if(!p_igetw(&dummyw,f))
373 return qe_invalid;
374
375 if(!p_igetw(&dummyw,f))
376 return qe_invalid;
377
378 if(!p_igetw(&dummyw,f))
379 return qe_invalid;
380
381 if(!p_igetw(&dummyw,f))
382 return qe_invalid;
383
384 if(!p_getc(&dummyc,f))
385 return qe_invalid;
386
387 if(!p_getc(&dummyc,f))
388 return qe_invalid;
389 }
390
391 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
392 {
393 readmapscreen(f, &header, &temp_mapscr, sversion);
394 }
395
396 readmapscreen(f, &header, &TheMaps[MAPSCRS+128], sversion);
397 readmapscreen(f, &header, &TheMaps[MAPSCRS+129], sversion);
398
399 pack_fclose(f);
400 clear_quest_tmpfile();
401
402 return true;
403 }
404
405 bool zmap::clearmap(bool newquest)
406 {
407 if(cursor.map<map_count)
408 {
409 for(int32_t i=0; i<MAPSCRS-(newquest?0:TEMPLATES); i++)
410 {
411 clearscr(i);
412 }
413
414 setCurrScr(0);
415
416 if(newquest)
417 {
418 if(!reset_templates(false))
419 {
420 jwin_alert("Error","Error resetting","template screens.",NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
421 }
422 }
423 }
424
425 return true;
426 }
427
428 MapCursor zmap::getCursor() const
429 {
430 return cursor;
431 }
432
433 11 void zmap::setCursor(MapCursor new_cursor)
434 {
435
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
11 if (cursor == new_cursor && screens)
436 return;
437
438
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (screens)
439 pushCursorToHistory(std::move(cursor));
440 11 cursor = std::move(new_cursor);
441
442
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (!screens) Color = -1;
443 11 screens = &TheMaps[cursor.map*MAPSCRS];
444
445 11 refresh_color();
446 11 setlayertarget();
447 11 reset_combo_animations2();
448 11 mmap_mark_dirty();
449 11 regions_mark_dirty();
450 11 }
451
452 void zmap::pushCursorToHistory(MapCursor cursor)
453 {
454 if (cursor_history_enabled)
455 {
456 cursor_undo_stack.push_back(std::move(cursor));
457 cursor_redo_stack = {};
458 CapCursorHistory();
459 }
460 }
461
462 bool zmap::isValidPosition(ComboPosition pos) const
463 {
464 return pos.is_valid(cursor);
465 }
466
467 int zmap::getScreenForPosition(ComboPosition pos) const
468 {
469 return cursor.viewscr + pos.screen_offset();
470 }
471
472 mapscr* zmap::CurrScr()
473 {
474 return screens+cursor.screen;
475 }
476 mapscr* zmap::Scr(int32_t scr)
477 {
478 return screens+scr;
479 }
480 mapscr* zmap::Scr(ComboPosition pos)
481 {
482 if (!pos.is_valid(cursor))
483 return nullptr;
484
485 int screen_offset = pos.screen_offset();
486 int screen = cursor.viewscr + screen_offset;
487 return AbsoluteScr(cursor.map, screen);
488 }
489 mapscr* zmap::Scr(ComboPosition pos, int layer)
490 {
491 int map = cursor.map;
492 int screen = cursor.viewscr + pos.screen_offset();
493 if (layer)
494 {
495 mapscr* scr = Map.AbsoluteScr(map, screen);
496 map = scr->layermap[CurrentLayer-1]-1;
497 screen = scr->layerscreen[CurrentLayer-1];
498 }
499
500 return AbsoluteScr(map, screen);
501 }
502 mapscr* zmap::ScrMakeValid(ComboPosition pos, int layer)
503 {
504 mapscr* scr = Scr(pos, layer);
505 if (scr && !(scr->valid&mVALID))
506 {
507 scr->valid |= mVALID;
508 setcolor(Color, scr);
509 }
510 return scr;
511 }
512 mapscr* zmap::AbsoluteScr(int32_t scr)
513 {
514 if(unsigned(scr) >= MAPSCRS*getMapCount())
515 return nullptr;
516 return &TheMaps[scr];
517 }
518 mapscr* zmap::AbsoluteScr(int32_t map, int32_t scr)
519 {
520 if(map < 0 || map >= getMapCount() || scr < 0 || scr >= MAPSCRS)
521 return nullptr;
522 return AbsoluteScr((map*MAPSCRS)+scr);
523 }
524 mapscr* zmap::AbsoluteScrMakeValid(int32_t map, int32_t screen)
525 {
526 mapscr* scr = AbsoluteScr(map, screen);
527 if (scr && !(scr->valid&mVALID))
528 {
529 scr->valid |= mVALID;
530 setcolor(Color, scr);
531 }
532 return scr;
533 }
534 void zmap::set_prvscr(int32_t map, int32_t scr)
535 {
536 prvscr = *get_canonical_scr(map, scr);
537
538 for(int32_t i=0; i<6; i++)
539 {
540 if(prvscr.layermap[i]>0)
541 {
542 prvlayers[i] = *get_canonical_scr(prvscr.layermap[i] - 1, prvscr.layerscreen[i]);
543 }
544 else
545 prvlayers[i].valid = 0;
546 }
547
548 prv_map=map;
549 prv_scr=scr;
550 }
551 92 int32_t zmap::getCurrMap()
552 {
553 92 return cursor.map;
554 }
555 11 void zmap::regions_mark_dirty()
556 {
557 11 regions_dirty = true;
558 11 }
559 void zmap::regions_refresh()
560 {
561 if (!regions_dirty)
562 return;
563
564 regions_dirty = false;
565 region_descriptions.clear();
566
567 current_map_region_ids = Regions[cursor.map].get_all_region_ids();
568 if (!get_all_region_descriptions(region_descriptions, current_map_region_ids))
569 region_descriptions.clear();
570 }
571 const std::vector<region_description>& zmap::get_region_descriptions()
572 {
573 regions_refresh();
574 return region_descriptions;
575 }
576 bool zmap::is_region(int screen)
577 {
578 if (screen < 0 || screen >= 128)
579 return false;
580
581 regions_refresh();
582 return current_map_region_ids[screen];
583 }
584 bool zmap::isDark(int scr)
585 {
586 return (screens[scr].flags&fDARK)!=0;
587 }
588 bool zmap::isValid(int32_t scr)
589 {
590 return (screens[scr].valid&mVALID)!=0;
591 }
592 bool zmap::isValid(int32_t map, int32_t scr)
593 {
594 return (AbsoluteScr(map, scr)->valid&mVALID)!=0;
595 }
596
597 void zmap::setCurrMap(int32_t index)
598 {
599 scrpos[cursor.map] = cursor.screen;
600 scrview[cursor.map] = cursor.viewscr;
601
602 auto new_cursor = cursor;
603 new_cursor.map = bound(index,0,map_count);
604
605 new_cursor.viewscr = scrview[new_cursor.map];
606 new_cursor.setScreen(scrpos[new_cursor.map]);
607 setCursor(std::move(new_cursor));
608 }
609
610 20 int32_t zmap::getCurrScr()
611 {
612 20 return cursor.screen;
613 }
614 void zmap::setCurrScr(int32_t scr)
615 {
616 if (scr == cursor.screen)
617 return;
618
619 auto new_cursor = cursor;
620 new_cursor.setScreen(scr);
621 setCursor(std::move(new_cursor));
622 }
623
624 int32_t zmap::getViewScr()
625 {
626 return cursor.viewscr;
627 }
628
629 void zmap::setViewSize(int32_t size)
630 {
631 auto new_cursor = cursor;
632 new_cursor.setSize(size);
633 setCursor(std::move(new_cursor));
634 }
635
636 1 int32_t zmap::getViewSize()
637 {
638 1 return cursor.size;
639 }
640
641 11 void zmap::setlayertarget()
642 {
643 11 layer_target_map = 0;
644 11 layer_target_multiple = 0;
645
646
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 11 times.
67 for(int32_t m=0; m<getMapCount(); ++m)
647 {
648
2/2
✓ Branch 0 taken 7616 times.
✓ Branch 1 taken 56 times.
7672 for(int32_t s=0; s<MAPSCRS; ++s)
649 {
650 7616 int32_t i=(m*MAPSCRS+s);
651 7616 mapscr *ts=&TheMaps[i];
652
653 // Search through each layer
654
2/2
✓ Branch 0 taken 45696 times.
✓ Branch 1 taken 7616 times.
53312 for(int32_t w=0; w<6; ++w)
655 {
656
3/4
✓ Branch 0 taken 15868 times.
✓ Branch 1 taken 29828 times.
✓ Branch 2 taken 15868 times.
✗ Branch 3 not taken.
45696 if(ts->layerscreen[w]==cursor.screen && (ts->layermap[w]-1)==cursor.map)
657 {
658 if(layer_target_map > 0)
659 {
660 layer_target_multiple += 1;
661 continue;
662 }
663
664 layer_target_map = m+1;
665 layer_target_scr = s;
666 }
667 45696 }
668 7616 }
669 56 }
670 11 }
671
672 11 void zmap::refresh_color()
673 {
674 11 auto color = getcolor();
675
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (Color != color)
676 {
677 11 loadlvlpal(color);
678 11 rebuild_trans_table();
679 11 }
680 11 }
681
682 void zmap::setcolor(int color, mapscr* scr)
683 {
684 if (!scr)
685 scr = CurrScr();
686 scr->valid |= mVALID;
687 scr->color = color;
688
689 refresh_color();
690
691 mmap_mark_dirty();
692 }
693
694 11 int32_t zmap::getcolor()
695 {
696 11 return getcolor(cursor.screen);
697 }
698
699 11 int32_t zmap::getcolor(int screen)
700 {
701
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 mapscr& scr = prv_mode ? prvscr : screens[screen];
702
703
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (scr.valid & mVALID)
704 11 return scr.color;
705
706 return map_infos[cursor.map].autopalette;
707 11 }
708
709 void zmap::resetflags()
710 {
711 byte *di=&(screens[cursor.screen].valid);
712
713 for(int32_t i=1; i<48; i++)
714 {
715 *(di+i)=0;
716 }
717 }
718
719 word zmap::tcmbdat(int32_t pos)
720 {
721 return screens[TEMPLATE].data[pos];
722 }
723
724 word zmap::tcmbcset(int32_t pos)
725 {
726 return screens[TEMPLATE].cset[pos];
727 }
728
729 int32_t zmap::tcmbflag(int32_t pos)
730 {
731 return screens[TEMPLATE].sflag[pos];
732 }
733
734 word zmap::tcmbdat2(int32_t pos)
735 {
736 return screens[TEMPLATE2].data[pos];
737 }
738
739 word zmap::tcmbcset2(int32_t pos)
740 {
741 return screens[TEMPLATE2].cset[pos];
742 }
743
744 int32_t zmap::tcmbflag2(int32_t pos)
745 {
746 return screens[TEMPLATE2].sflag[pos];
747 }
748
749 void zmap::TemplateAll()
750 {
751 StartListCommand();
752 for(int32_t i=0; i<128; i++)
753 {
754 if((screens[i].valid&mVALID) && isDungeon(i))
755 DoTemplateCommand(-1, -1, i);
756 }
757 FinishListCommand();
758 }
759
760 void zmap::Template(int32_t floorcombo, int32_t floorcset, int32_t scr)
761 {
762 if(scr==TEMPLATE)
763 return;
764
765 if(!(screens[scr].valid&mVALID))
766 screens[scr].color=Color;
767
768 screens[scr].valid|=mVALID;
769
770 for(int32_t i=0; i<32; i++)
771 {
772 screens[scr].data[i]=screens[TEMPLATE].data[i];
773 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
774 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
775 }
776
777 for(int32_t i=144; i<176; i++)
778 {
779 screens[scr].data[i]=screens[TEMPLATE].data[i];
780 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
781 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
782 }
783
784 for(int32_t y=2; y<=9; y++)
785 {
786 int32_t j=y<<4;
787 screens[scr].data[j]=screens[TEMPLATE].data[j];
788 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
789 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
790 ++j;
791 screens[scr].data[j]=screens[TEMPLATE].data[j];
792 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
793 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
794 ++j;
795 j+=12;
796 screens[scr].data[j]=screens[TEMPLATE].data[j];
797 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
798 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
799 ++j;
800 screens[scr].data[j]=screens[TEMPLATE].data[j];
801 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
802
803 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
804 ++j;
805 }
806
807 if(floorcombo!=-1)
808 {
809 for(int32_t y=2; y<9; y++)
810 for(int32_t x=2; x<14; x++)
811 {
812 int32_t i=(y<<4)+x;
813 screens[scr].data[i] = floorcombo;
814 screens[scr].cset[i] = floorcset;
815 }
816 }
817
818 for(int32_t i=0; i<4; i++)
819 putdoor(scr,i,screens[scr].door[i]);
820 }
821
822
823 void zmap::clearscr(int32_t scr)
824 {
825 screens[scr].zero_memory();
826 screens[scr].valid=mVERSION;
827 auto const& mapinf = map_infos[cursor.map];
828 for(int q = 0; q < 6; ++q)
829 {
830 auto layer = mapinf.autolayers[q];
831 screens[scr].layermap[q] = layer;
832 screens[scr].layerscreen[q] = layer ? scr : 0;
833 }
834 screens[scr].color = mapinf.autopalette;
835 if (scr == cursor.screen)
836 refresh_color();
837 mmap_mark_dirty();
838 }
839
840 const char *loaderror[] =
841 {
842
843 "OK","File not found","Incomplete data",
844 "Invalid version","Invalid file"
845
846 };
847
848 int32_t zmap::load(const char *path)
849 {
850 PACKFILE *f=pack_fopen_password(path,F_READ, "");
851
852 if(!f)
853 return 1;
854
855
856 int16_t version;
857 byte build;
858
859 //get the version
860 if(!p_igetw(&version,f))
861 {
862 goto file_error;
863 }
864
865 //get the build
866 if(!p_getc(&build,f))
867 {
868 goto file_error;
869 }
870
871 for(int32_t i=0; i<MAPSCRS; i++)
872 {
873 mapscr tmpimportscr;
874 tmpimportscr.zero_memory();
875 if(readmapscreen(f,&header,&tmpimportscr,version)==qe_invalid)
876 {
877 al_trace("failed zmap::load\n");
878 goto file_error;
879 }
880
881 switch(ImportMapBias)
882 {
883 case 0:
884 *(screens+i) = tmpimportscr;
885 break;
886
887 case 1:
888 if(!(screens[i].valid&mVALID))
889 {
890 *(screens+i) = tmpimportscr;
891 }
892 break;
893
894 case 2:
895 if(tmpimportscr.valid&mVALID)
896 {
897 *(screens+i) = tmpimportscr;
898 }
899 break;
900 }
901 }
902
903
904 pack_fclose(f);
905
906 setCurrScr(0);
907 mmap_mark_dirty();
908 regions_mark_dirty();
909 return 0;
910
911 file_error:
912 pack_fclose(f);
913 clearmap(false);
914 return 2;
915 }
916
917 int32_t zmap::save(const char *path)
918 {
919 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
920
921 if(!f)
922 return 1;
923
924 if(!p_iputw(V_MAPS,f))
925 {
926 pack_fclose(f);
927 return 3;
928 }
929
930 // This was the "build number", but that's totally useless here. Keep this junk byte
931 // so as not to totally break exports between ZC versions.
932 if(!p_putc(0,f))
933 {
934 pack_fclose(f);
935 return 3;
936 }
937
938 for(int32_t i=0; i<MAPSCRS; i++)
939 {
940 if(writemapscreen(f,this->getCurrMap(),i) == qe_invalid)
941 {
942 pack_fclose(f);
943 return 2;
944 }
945 }
946
947 pack_fclose(f);
948 return 0;
949 }
950
951
952 bool zmap::ishookshottable(int32_t bx, int32_t by, int32_t i)
953 {
954 // Hookshots can be blocked by solid combos on all 3 ground layers.
955 const newcombo* c = &combobuf[MAPCOMBO(bx,by)];
956
957 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
958 return true;
959 if (c->walk&(1<<i))
960 return false;
961
962 for(int32_t k=0; k<2; k++)
963 {
964 c = &combobuf[MAPCOMBO2(k+1,bx,by)];
965
966 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
967 {
968 return false;
969 }
970 }
971
972 return true;
973 }
974
975 bool zmap::ishookshottable(int32_t map, int32_t screen, int32_t bx, int32_t by, int32_t i)
976 {
977 // Hookshots can be blocked by solid combos on all 3 ground layers.
978 const newcombo* c = &combobuf[MAPCOMBO3(map, screen, -1, bx,by)];
979
980 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
981 return true;
982 if (c->walk&(1<<i))
983 return false;
984
985 for(int32_t k=0; k<2; k++)
986 {
987 c = &combobuf[MAPCOMBO3(map, screen, k+1,bx,by)];
988
989 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
990 {
991 return false;
992 }
993 }
994
995 return true;
996 }
997
998 bool zmap::isstepable(int32_t combo)
999 {
1000 // This is kind of odd but it's true to the engine (see maps.cpp)
1001 return (combo_class_buf[combobuf[combo].type].ladder_pass);
1002 }
1003
1004 // Returns the letter of the warp combo.
1005 int32_t zmap::warpindex(int32_t combo)
1006 {
1007 switch(combobuf[combo].type)
1008 {
1009 case cCAVE:
1010 case cPIT:
1011 case cSTAIR:
1012 case cCAVE2:
1013 case cSWIMWARP:
1014 case cDIVEWARP:
1015 case cSWARPA:
1016 return 0;
1017
1018 case cCAVEB:
1019 case cPITB:
1020 case cSTAIRB:
1021 case cCAVE2B:
1022 case cSWIMWARPB:
1023 case cDIVEWARPB:
1024 case cSWARPB:
1025 return 1;
1026
1027 case cCAVEC:
1028 case cPITC:
1029 case cSTAIRC:
1030 case cCAVE2C:
1031 case cSWIMWARPC:
1032 case cDIVEWARPC:
1033 case cSWARPC:
1034 return 2;
1035
1036 case cCAVED:
1037 case cPITD:
1038 case cSTAIRD:
1039 case cCAVE2D:
1040 case cSWIMWARPD:
1041 case cDIVEWARPD:
1042 case cSWARPD:
1043 return 3;
1044
1045 case cPITR:
1046 case cSTAIRR:
1047 case cSWARPR:
1048 return 4;
1049 }
1050
1051 return -1;
1052
1053 }
1054
1055 void draw_ladder(BITMAP* dest, int32_t x, int32_t y, int32_t c, bool top = false)
1056 {
1057 if(top)
1058 line(dest,x,y,x+15,y,c);
1059 rectfill(dest,x,y,x+3,y+15,c);
1060 rectfill(dest,x+12,y,x+15,y+15,c);
1061 rectfill(dest,x+4,y+2,x+11,y+5,c);
1062 rectfill(dest,x+4,y+10,x+11,y+13,c);
1063 }
1064
1065 void draw_platform(BITMAP* dest, int32_t x, int32_t y, int32_t c)
1066 {
1067 line(dest,x,y,x+15,y,c);
1068 }
1069
1070 void zmap::put_walkflags_layered(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer)
1071 {
1072 int32_t cx = COMBOX(pos);
1073 int32_t cy = COMBOY(pos);
1074
1075 newcombo const& c = combobuf[ MAPCOMBO2(layer,cx,cy) ];
1076
1077 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1078
1079 int32_t bridgedetected = 0;
1080
1081 for(int32_t i=0; i<4; i++)
1082 {
1083 int32_t tx=((i&2)<<2)+x;
1084 int32_t ty=((i&1)<<3)+y;
1085 int32_t tx2=((i&2)<<2)+cx;
1086 int32_t ty2=((i&1)<<3)+cy;
1087 for (int32_t m = layer; m <= 1; m++)
1088 {
1089 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1090 {
1091 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1092 {
1093 bridgedetected |= (1<<i);
1094 }
1095 }
1096 else
1097 {
1098 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1099 {
1100 bridgedetected |= (1<<i);
1101 }
1102 }
1103 }
1104 if (bridgedetected & (1<<i))
1105 {
1106 if (i >= 3) break;
1107 else continue;
1108 }
1109 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1110 {
1111 for(int32_t k=0; k<8; k+=2)
1112 for(int32_t j=0; j<8; j+=2)
1113 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1114 }
1115 if (!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1116 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1117
1118 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1119 {
1120 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO(cx,cy)) && ishookshottable(cx,cy,i))
1121 {
1122 for(int32_t k=0; k<8; k+=2)
1123 for(int32_t j=0; j<8; j+=2)
1124 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1125 }
1126 else
1127 {
1128 int32_t color = COLOR_SOLID;
1129
1130 if(isstepable(MAPCOMBO(cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || (combo_class_buf[combobuf[MAPCOMBO(cx,cy)].type].water==0 && combo_class_buf[c.type].water==0)))
1131 color=vc(6);
1132 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(cx,cy,i))
1133 color=vc(7);
1134
1135 rectfill(dest,tx,ty,tx+7,ty+7,color);
1136 }
1137 }
1138 }
1139
1140 bridgedetected = 0;
1141 for(int32_t i=0; i<4; i++)
1142 {
1143 int32_t tx2=((i&2)<<2)+cx;
1144 int32_t ty2=((i&1)<<3)+cy;
1145 for (int32_t m = 0; m <= 1; m++)
1146 {
1147 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1148 {
1149 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1150 {
1151 bridgedetected |= (1<<i);
1152 }
1153 }
1154 else
1155 {
1156 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1157 {
1158 bridgedetected |= (1<<i);
1159 }
1160 }
1161 }
1162 }
1163
1164 // Draw damage combos
1165 newcombo const& c0 = combobuf[MAPCOMBO2(-1,cx,cy)];
1166 newcombo const& c1 = combobuf[MAPCOMBO2(0,cx,cy)];
1167 newcombo const& c2 = combobuf[MAPCOMBO2(1,cx,cy)];
1168 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1169 || combo_class_buf[c1.type].modify_hp_amount
1170 || combo_class_buf[c2.type].modify_hp_amount;
1171
1172 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1173
1174 if(dmg)
1175 {
1176 if (bridgedetected <= 0)
1177 {
1178 for(int32_t k=0; k<16; k+=2)
1179 for(int32_t j=0; j<16; j+=2)
1180 if(((k+j)/2)%2)
1181 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1182 }
1183 else
1184 {
1185 for(int32_t i=0; i<4; i++)
1186 {
1187 if (!(bridgedetected & (1<<i)))
1188 {
1189 int32_t tx=((i&2)<<2)+x;
1190 int32_t ty=((i&1)<<3)+y;
1191 for(int32_t k=0; k<8; k+=2)
1192 for(int32_t j=0; j<8; j+=2)
1193 if(((k+j)/2)%2)
1194 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1195 }
1196 }
1197 }
1198 }
1199
1200 if(c.type == cSLOPE)
1201 {
1202 slope_info s(c, x, y);
1203 s.draw(dest, 0, 0, COLOR_SLOPE);
1204 }
1205 auto fl0 = MAPFLAG2(-1,cx,cy);
1206 auto fl1 = MAPFLAG2(0,cx,cy);
1207 auto fl2 = MAPFLAG2(1,cx,cy);
1208 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1209 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1210 {
1211 bool top = false;
1212 if(cy)
1213 {
1214 top = true;
1215 if(combobuf[MAPCOMBO2(-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1216 || combobuf[MAPCOMBO2(0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1217 || combobuf[MAPCOMBO2(1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1218 || MAPFLAG2(-1,cx,cy) == mfSIDEVIEWLADDER
1219 || MAPFLAG2(0,cx,cy) == mfSIDEVIEWLADDER
1220 || MAPFLAG2(1,cx,cy) == mfSIDEVIEWLADDER)
1221 {
1222 top = false;
1223 }
1224 }
1225 draw_ladder(dest,x,y,COLOR_LADDER,top);
1226 }
1227 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1228 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1229 {
1230 draw_platform(dest,x,y,COLOR_LADDER);
1231 }
1232 }
1233
1234 void zmap::put_walkflags_layered_external(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer, int32_t map, int32_t screen)
1235 {
1236 int32_t cx = COMBOX(pos);
1237 int32_t cy = COMBOY(pos);
1238
1239 if (screen < 0) return;
1240 if (map < 0) return;
1241
1242 newcombo const& c = combobuf[MAPCOMBO3(map, screen, layer, pos)];
1243
1244 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1245
1246 int32_t bridgedetected = 0;
1247 for(int32_t i=0; i<4; i++)
1248 {
1249 int32_t tx=((i&2)<<2)+x;
1250 int32_t ty=((i&1)<<3)+y;
1251 int32_t tx2=((i&2)<<2)+cx;
1252 int32_t ty2=((i&1)<<3)+cy;
1253 for (int32_t m = layer; m <= 1; m++)
1254 {
1255 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1256 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1257 {
1258 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1259 {
1260 bridgedetected |= (1<<i);
1261 }
1262 }
1263 else
1264 {
1265 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1266 {
1267 bridgedetected |= (1<<i);
1268 }
1269 }
1270 }
1271 if (bridgedetected & (1<<i))
1272 {
1273 continue;
1274 }
1275 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1276 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1277
1278
1279 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1280 {
1281 for(int32_t k=0; k<8; k+=2)
1282 for(int32_t j=0; j<8; j+=2)
1283 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1284 }
1285 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1286 {
1287 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO3(map, screen, layer, cx,cy)) && ishookshottable(map, screen, cx,cy,i) && layer < 0)
1288 {
1289 for(int32_t k=0; k<8; k+=2)
1290 for(int32_t j=0; j<8; j+=2)
1291 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1292 }
1293 else
1294 {
1295 int32_t color = COLOR_SOLID;
1296
1297 if(isstepable(MAPCOMBO3(map, screen, -1, cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || combo_class_buf[combobuf[MAPCOMBO3(map, screen, -1, cx,cy)].type].water==0))
1298 color=vc(6);
1299 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(map, screen, cx,cy,i))
1300 color=vc(7);
1301
1302 rectfill(dest,tx,ty,tx+7,ty+7,color);
1303 }
1304 }
1305 }
1306
1307 bridgedetected = 0;
1308 for(int32_t i=0; i<4; i++)
1309 {
1310 int32_t tx2=((i&2)<<2)+cx;
1311 int32_t ty2=((i&1)<<3)+cy;
1312 for (int32_t m = 0; m <= 1; m++)
1313 {
1314 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1315 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1316 {
1317 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1318 {
1319 bridgedetected |= (1<<i);
1320 }
1321 }
1322 else
1323 {
1324 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1325 {
1326 bridgedetected |= (1<<i);
1327 }
1328 }
1329 }
1330 }
1331
1332 // Draw damage combos
1333 newcombo const& c0 = combobuf[MAPCOMBO3(map, screen, -1,pos)];
1334 newcombo const& c1 = combobuf[MAPCOMBO3(map, screen, 0,pos)];
1335 newcombo const& c2 = combobuf[MAPCOMBO3(map, screen, 1,pos)];
1336 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1337 || combo_class_buf[c1.type].modify_hp_amount
1338 || combo_class_buf[c2.type].modify_hp_amount;
1339
1340 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1341
1342 if(dmg)
1343 {
1344 if (bridgedetected <= 0)
1345 {
1346 for(int32_t k=0; k<16; k+=2)
1347 for(int32_t j=0; j<16; j+=2)
1348 if(((k+j)/2)%2)
1349 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1350 }
1351 else
1352 {
1353 for(int32_t i=0; i<4; i++)
1354 {
1355 if (!(bridgedetected & (1<<i)))
1356 {
1357 int32_t tx=((i&2)<<2)+x;
1358 int32_t ty=((i&1)<<3)+y;
1359 for(int32_t k=0; k<8; k+=2)
1360 for(int32_t j=0; j<8; j+=2)
1361 if(((k+j)/2)%2)
1362 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1363 }
1364 }
1365 }
1366 }
1367
1368 if(c.type == cSLOPE)
1369 {
1370 slope_info s(c, x, y);
1371 s.draw(dest, 0, 0, COLOR_SLOPE);
1372 }
1373 auto fl0 = MAPFLAG3(map,screen,-1,pos);
1374 auto fl1 = MAPFLAG3(map,screen,0,pos);
1375 auto fl2 = MAPFLAG3(map,screen,1,pos);
1376 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1377 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1378 {
1379 bool top = false;
1380 if(cy)
1381 {
1382 top = true;
1383 if(combobuf[MAPCOMBO3(map,screen,-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1384 || combobuf[MAPCOMBO3(map,screen,0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1385 || combobuf[MAPCOMBO3(map,screen,1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1386 || MAPFLAG3(map,screen,-1,cx,cy-16) == mfSIDEVIEWLADDER
1387 || MAPFLAG3(map,screen,0,cx,cy-16) == mfSIDEVIEWLADDER
1388 || MAPFLAG3(map,screen,1,cx,cy-16) == mfSIDEVIEWLADDER)
1389 {
1390 top = false;
1391 }
1392 }
1393 draw_ladder(dest,x,y,COLOR_LADDER,top);
1394 }
1395 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1396 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1397 {
1398 draw_platform(dest,x,y,COLOR_LADDER);
1399 }
1400 }
1401
1402 void put_walkflags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t layer)
1403 {
1404 const newcombo& c = combobuf[cmbdat];
1405
1406 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1407
1408 for(int32_t i=0; i<4; i++)
1409 {
1410 int32_t tx=((i&2)<<2)+x;
1411 int32_t ty=((i&1)<<3)+y;
1412
1413 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && combo_class_buf[c.type].water!=0)
1414 {
1415 if ((layer==0 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 1) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 2)) && get_qr(qr_DROWN))
1416 {
1417 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1418 }
1419 else
1420 {
1421 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1422 }
1423 }
1424
1425
1426 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1427 {
1428 for(int32_t k=0; k<8; k+=2)
1429 for(int32_t j=0; j<8; j+=2)
1430 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1431 }
1432 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1433 {
1434 if(c.type==cLADDERHOOKSHOT)
1435 {
1436 for(int32_t k=0; k<8; k+=2)
1437 for(int32_t j=0; j<8; j+=2)
1438 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1439 }
1440 else
1441 {
1442 int32_t color = COLOR_SOLID;
1443
1444 if(c.type==cLADDERONLY)
1445 color=vc(6);
1446 else if(c.type==cHOOKSHOTONLY)
1447 color=vc(7);
1448
1449 rectfill(dest,tx,ty,tx+7,ty+7,color);
1450 }
1451 }
1452
1453 // Draw damage combos
1454 if(combo_class_buf[c.type].modify_hp_amount != 0)
1455 {
1456 for(int32_t k=0; k<8; k+=2)
1457 for(int32_t j=0; j<8; j+=2)
1458 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(4));
1459 }
1460 }
1461
1462 if(c.type == cSLOPE)
1463 {
1464 slope_info s(c, 0, 0);
1465 zfix const& slope = s.slope();
1466
1467 BITMAP* sub = create_bitmap_ex(8,16,16);
1468 clear_bitmap(sub);
1469 s.draw(sub, 0, 0, COLOR_SLOPE);
1470 masked_blit(sub, dest, 0, 0, x, y, 16, 16);
1471 destroy_bitmap(sub);
1472 }
1473 if(c.flag == mfSIDEVIEWLADDER)
1474 {
1475 draw_ladder(dest,x,y,COLOR_LADDER);
1476 }
1477 else if(c.flag == mfSIDEVIEWPLATFORM)
1478 {
1479 draw_platform(dest,x,y,COLOR_LADDER);
1480 }
1481 }
1482
1483 void put_flag(BITMAP* dest, int32_t x, int32_t y, int32_t flag)
1484 {
1485 rectfill(dest,x,y,x+15,y+15,vc(flag&15));
1486 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(flag&15)),-1,"%d",flag);
1487 }
1488 void put_flags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1489 {
1490
1491 newcombo const& c = combobuf[cmbdat];
1492
1493 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1494 {
1495 // rectfill(dest,x,y,x+15,y+15,vc(cmbdat>>10+1));
1496 // text_mode(-1);
1497 // textprintf_ex(dest,get_zc_font(font_sfont),x+1,y+1,(sflag)==0x7800?vc(0):vc(15),-1,"%d",sflag);
1498 if(sflag)
1499 {
1500 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1501 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1502 }
1503
1504 if(c.flag)
1505 {
1506 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1507 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1508 }
1509 }
1510
1511 if(flags&cCSET)
1512 {
1513 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1514 // text_mode(inv?vc(15):vc(0));
1515 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1516 }
1517 else if(flags&cCTYPE)
1518 {
1519 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1520 // text_mode(inv?vc(15):vc(0));
1521 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1522 }
1523 }
1524
1525 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag,int32_t scale)
1526 {
1527 bool repos = combotile_override_x < 0 && combotile_override_y < 0;
1528
1529 BITMAP* b = create_bitmap_ex(8,scale*16,scale*16);
1530 if(repos)
1531 {
1532 combotile_override_x = x+(8*(scale-1));
1533 combotile_override_y = y+(8*(scale-1));
1534 }
1535 put_combo(b,0,0,cmbdat,cset,flags,sflag);
1536 if(repos) combotile_override_x = combotile_override_y = -1;
1537 masked_stretch_blit(b,dest,0,0,16,16,x,y,16*scale,16*scale);
1538 destroy_bitmap(b);
1539 }
1540 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1541 {
1542 static newcombo nilcombo;
1543 nilcombo.tile = 0;
1544
1545 newcombo const& c = cmbdat < MAXCOMBOS ? combobuf[cmbdat] : nilcombo;
1546
1547 if(c.tile==0)
1548 {
1549 rectfill(dest,x,y,x+15,y+15,vc(0));
1550 rectfill(dest,x+3,y+3,x+12,y+12,vc(4));
1551 return;
1552 }
1553
1554 putcombo(dest,x,y,cmbdat,cset);
1555
1556 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1557 {
1558 if(sflag)
1559 {
1560 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1561 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1562 }
1563
1564 if(combobuf[cmbdat].flag)
1565 {
1566 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1567 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1568 }
1569 }
1570
1571 if(flags&cWALK)
1572 {
1573 put_walkflags(dest,x,y,cmbdat,0);
1574 }
1575
1576 if(flags&cCSET)
1577 {
1578 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1579 // text_mode(inv?vc(15):vc(0));
1580 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1581 }
1582 else if(flags&cCTYPE)
1583 {
1584 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1585 // text_mode(inv?vc(15):vc(0));
1586 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1587 }
1588 }
1589 void put_engraving(BITMAP* dest, int32_t x, int32_t y, int32_t slot, int32_t scale)
1590 {
1591 auto blitx = 1 + (slot % 16) * 17;
1592 auto blity = 1 + (slot / 16) * 17;
1593 masked_stretch_blit(asset_engravings_bmp, dest, blitx, blity, 16, 16, x, y, 16 * scale, 16 * scale);
1594 }
1595
1596
1597 void copy_mapscr(mapscr *dest, const mapscr *src)
1598 {
1599 if(!dest || !src) return;
1600 *dest = *src;
1601 }
1602
1603 void zmap::put_door(BITMAP *dest,int32_t pos,int32_t side,int32_t type,int32_t xofs,int32_t yofs,bool ignorepos, int32_t scr)
1604 {
1605 int32_t x=0,y=0;
1606 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1607
1608 switch(side)
1609 {
1610 case up:
1611 case down:
1612 x=((pos&15)<<4)+xofs;
1613 y=(ignorepos?0:(pos&0xF0))+yofs;
1614 break;
1615
1616 case left:
1617 case right:
1618 x=(ignorepos?0:((pos&15)<<4))+xofs;
1619 y=(pos&0xF0)+yofs;
1620 break;
1621 }
1622
1623 switch(type)
1624 {
1625 case dt_lock:
1626 case dt_shut:
1627 case dt_boss:
1628 case dt_bomb:
1629 switch(side)
1630 {
1631 case up:
1632 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][0],
1633 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][0],0,0);
1634 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][1],
1635 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][1],0,0);
1636 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][2],
1637 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][2],0,0);
1638 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][3],
1639 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][3],0,0);
1640 break;
1641
1642 case down:
1643 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][0],
1644 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][0],0,0);
1645 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][1],
1646 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][1],0,0);
1647 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][2],
1648 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][2],0,0);
1649 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][3],
1650 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][3],0,0);
1651 break;
1652
1653 case left:
1654 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][0],
1655 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][0],0,0);
1656 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][2],
1657 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][2],0,0);
1658 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][4],
1659 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][4],0,0);
1660
1661 if(x+16 >= dest->w)
1662 break;
1663
1664 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][1],
1665 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][1],0,0);
1666 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][3],
1667 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][3],0,0);
1668 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][5],
1669 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][5],0,0);
1670 break;
1671
1672 case right:
1673
1674 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][1],
1675 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][1],0,0);
1676 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][3],
1677 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][3],0,0);
1678 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][5],
1679 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][5],0,0);
1680
1681 if(x+16 <= 0)
1682 break;
1683
1684 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][0],
1685 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][0],0,0);
1686 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][2],
1687 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][2],0,0);
1688 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][4],
1689 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][4],0,0);
1690 break;
1691 }
1692
1693 break;
1694
1695 case dt_pass:
1696 case dt_wall:
1697 case dt_walk:
1698 default:
1699 break;
1700 }
1701 }
1702
1703 void zmap::over_door(BITMAP *dest,int32_t pos,int32_t side,int32_t xofs,int32_t yofs,bool, int32_t scr)
1704 {
1705 int32_t x=((pos&15)<<4)+xofs;
1706 int32_t y=(pos&0xF0)+yofs;
1707 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1708
1709
1710 switch(side)
1711 {
1712 case up:
1713 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0]!=0)
1714 {
1715 overcombo(dest,x,y,
1716 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0],
1717 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[0]);
1718 }
1719
1720 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1]!=0)
1721 {
1722 overcombo(dest,x+16,y,
1723 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1],
1724
1725 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[1]);
1726 }
1727
1728 break;
1729
1730 case down:
1731 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0]!=0)
1732 {
1733 overcombo(dest,x,y,
1734 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0],
1735 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[0]);
1736 }
1737
1738 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1]!=0)
1739 {
1740 overcombo(dest,x+16,y,
1741 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1],
1742 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[1]);
1743 }
1744
1745 break;
1746
1747 case left:
1748 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0]!=0)
1749 {
1750 overcombo(dest,x,y,
1751 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0],
1752 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[0]);
1753 }
1754
1755 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1]!=0)
1756 {
1757 overcombo(dest,x,y+16,
1758 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1],
1759 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[1]);
1760 }
1761
1762 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2]!=0)
1763 {
1764 overcombo(dest,x,y+32,
1765 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2],
1766 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[2]);
1767 }
1768
1769 break;
1770
1771 case right:
1772 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0]!=0)
1773 {
1774 overcombo(dest,x,y,
1775 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0],
1776 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[0]);
1777 }
1778
1779 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1]!=0)
1780 {
1781 overcombo(dest,x,y+16,
1782
1783 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1],
1784 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[1]);
1785 }
1786
1787 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2]!=0)
1788 {
1789 overcombo(dest,x,y+32,
1790 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2],
1791 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[2]);
1792 }
1793
1794 break;
1795 }
1796 }
1797
1798 bool zmap::misaligned(int32_t map, int32_t screen, int32_t i, int32_t dir)
1799 {
1800 word cmbcheck1, cmbcheck2;
1801 newcombo combocheck1, combocheck2;
1802 combocheck1 = combobuf[0];
1803 combocheck2 = combobuf[0];
1804 combocheck1.walk = 0;
1805 combocheck2.walk = 0;
1806
1807 int32_t layermap, layerscreen;
1808
1809 switch(dir)
1810 {
1811 case up:
1812 {
1813 if(i>15) //not top row of combos
1814 {
1815 return false;
1816 }
1817
1818 if(screen<16) //top row of screens
1819 {
1820 return false;
1821
1822 }
1823
1824 //check main screen
1825 cmbcheck1 = vbound(AbsoluteScr(map, screen)->data[i], 0, MAXCOMBOS-1);
1826 cmbcheck2 = vbound(AbsoluteScr(map, screen-16)->data[i+160], 0, MAXCOMBOS-1);
1827 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1828 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1829
1830 //check layer 1
1831 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
1832
1833 if(layermap>-1 && layermap<map_count)
1834 {
1835 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
1836 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1837 if (combobuf[cmbcheck1].type == cBRIDGE)
1838 {
1839 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1840 {
1841 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1842 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1843 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1844 }
1845 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1846 }
1847 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1848 }
1849
1850 layermap=AbsoluteScr(map, screen-16)->layermap[0]-1;
1851
1852 if(layermap>-1 && layermap<map_count)
1853 {
1854 layerscreen=AbsoluteScr(map, screen-16)->layerscreen[0];
1855 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1856 if (combobuf[cmbcheck2].type == cBRIDGE)
1857 {
1858 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1859 {
1860 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1861 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1862 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1863 }
1864 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1865 }
1866 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1867 }
1868
1869 //check layer 2
1870 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
1871
1872 if(layermap>-1 && layermap<map_count)
1873 {
1874 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
1875
1876 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1877 if (combobuf[cmbcheck2].type == cBRIDGE)
1878 {
1879 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1880 {
1881 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1882 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1883 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1884 }
1885 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1886 }
1887 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1888 }
1889
1890 layermap=AbsoluteScr(map, screen-16)->layermap[1]-1;
1891
1892 if(layermap>-1 && layermap<map_count)
1893 {
1894 layerscreen=AbsoluteScr(map, screen-16)->layerscreen[1];
1895 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1896 if (combobuf[cmbcheck2].type == cBRIDGE)
1897 {
1898 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1899 {
1900 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1901 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1902 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1903 }
1904 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1905 }
1906 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1907 }
1908
1909 if(((combocheck1.walk&5)*2)!=(combocheck2.walk&10))
1910 {
1911 return true;
1912 }
1913
1914 break;
1915 }
1916 case down:
1917 {
1918 if(i<160) //not bottom row of combos
1919 {
1920 return false;
1921 }
1922
1923 if(screen>111) //bottom row of screens
1924 {
1925 return false;
1926 }
1927
1928 //check main screen
1929 cmbcheck1 = vbound(AbsoluteScr(map, screen)->data[i], 0, MAXCOMBOS-1);
1930 cmbcheck2 = vbound(AbsoluteScr(map, screen+16)->data[i-160], 0, MAXCOMBOS-1);
1931 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1932 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1933
1934
1935 //check layer 1
1936 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
1937
1938 if(layermap>-1 && layermap<map_count)
1939 {
1940 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
1941 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1942 if (combobuf[cmbcheck1].type == cBRIDGE)
1943 {
1944 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1945 {
1946 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1947 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1948 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1949 }
1950 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1951 }
1952 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1953 }
1954
1955 layermap=AbsoluteScr(map, screen+16)->layermap[0]-1;
1956
1957 if(layermap>-1 && layermap<map_count)
1958 {
1959 layerscreen=AbsoluteScr(map, screen+16)->layerscreen[0];
1960 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1961 if (combobuf[cmbcheck2].type == cBRIDGE)
1962 {
1963 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1964 {
1965 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1966 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1967 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1968 }
1969 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1970 }
1971 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1972 }
1973
1974 //check layer 2
1975 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
1976
1977 if(layermap>-1 && layermap<map_count)
1978 {
1979 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
1980 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1981 if (combobuf[cmbcheck1].type == cBRIDGE)
1982 {
1983 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1984 {
1985 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1986 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1987 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1988 }
1989 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1990 }
1991 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1992 }
1993
1994 layermap=AbsoluteScr(map, screen+16)->layermap[1]-1;
1995
1996 if(layermap>-1 && layermap<map_count)
1997 {
1998 layerscreen=AbsoluteScr(map, screen+16)->layerscreen[1];
1999 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
2000 if (combobuf[cmbcheck2].type == cBRIDGE)
2001 {
2002 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2003 {
2004 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2005 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2006 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2007 }
2008 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2009 }
2010 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2011 }
2012
2013 if((combocheck1.walk&10)!=((combocheck2.walk&5)*2))
2014 {
2015 return true;
2016 }
2017
2018 break;
2019 }
2020 case left:
2021 {
2022 if((i&0xF)!=0) //not left column of combos
2023 {
2024 return false;
2025 }
2026
2027 if((screen&0xF)==0) //left column of screens
2028 {
2029 return false;
2030 }
2031
2032 //check main screen
2033 cmbcheck1 = AbsoluteScr(map, screen)->data[i];
2034 cmbcheck2 = AbsoluteScr(map, screen-1)->data[i+15];
2035 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2036 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2037
2038 //check layer 1
2039 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
2040
2041 if(layermap>-1 && layermap<map_count)
2042 {
2043 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
2044 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2045 if (combobuf[cmbcheck1].type == cBRIDGE)
2046 {
2047 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2048 {
2049 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2050 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2051 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2052 }
2053 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2054 }
2055 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2056 }
2057
2058 layermap=AbsoluteScr(map, screen-1)->layermap[0]-1;
2059
2060 if(layermap>-1 && layermap<map_count)
2061 {
2062 layerscreen=AbsoluteScr(map, screen-1)->layerscreen[0];
2063 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2064 if (combobuf[cmbcheck2].type == cBRIDGE)
2065 {
2066 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2067 {
2068 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2069 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2070 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2071 }
2072 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2073 }
2074 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2075 }
2076
2077 //check layer 2
2078 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
2079
2080 if(layermap>-1 && layermap<map_count)
2081 {
2082 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
2083 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2084 if (combobuf[cmbcheck1].type == cBRIDGE)
2085 {
2086 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2087 {
2088 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2089 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2090 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2091 }
2092 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2093 }
2094 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2095 }
2096
2097 layermap=AbsoluteScr(map, screen-1)->layermap[1]-1;
2098
2099 if(layermap>-1 && layermap<map_count)
2100 {
2101 layerscreen=AbsoluteScr(map, screen-1)->layerscreen[1];
2102 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2103 if (combobuf[cmbcheck2].type == cBRIDGE)
2104 {
2105 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2106 {
2107 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2108 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2109 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2110 }
2111 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2112 }
2113 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2114 }
2115
2116 if(((combocheck1.walk&3)*4)!=(combocheck2.walk&12))
2117 {
2118 return true;
2119 }
2120
2121 break;
2122 }
2123 case right:
2124 {
2125 if((i&0xF)!=15) //not right column of combos
2126 {
2127 return false;
2128 }
2129
2130 if((screen&0xF)==15) //right column of screens
2131 {
2132 return false;
2133 }
2134
2135 //check main screen
2136 cmbcheck1 = AbsoluteScr(map, screen)->data[i];
2137 cmbcheck2 = AbsoluteScr(map, screen+1)->data[i-15];
2138 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2139 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2140
2141 //check layer 1
2142 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
2143
2144 if(layermap>-1 && layermap<map_count)
2145 {
2146 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
2147 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2148 if (combobuf[cmbcheck1].type == cBRIDGE)
2149 {
2150 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2151 {
2152 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2153 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2154 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2155 }
2156 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2157 }
2158 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2159 }
2160
2161 layermap=AbsoluteScr(map, screen+1)->layermap[0]-1;
2162
2163 if(layermap>-1 && layermap<map_count)
2164 {
2165 layerscreen=AbsoluteScr(map, screen+1)->layerscreen[0];
2166 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2167 if (combobuf[cmbcheck2].type == cBRIDGE)
2168 {
2169 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2170 {
2171 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2172 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2173 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2174 }
2175 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2176 }
2177 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2178 }
2179
2180 //check layer 2
2181 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
2182
2183 if(layermap>-1 && layermap<map_count)
2184 {
2185 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
2186 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2187 if (combobuf[cmbcheck1].type == cBRIDGE)
2188 {
2189 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2190 {
2191 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2192 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2193 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2194 }
2195 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2196 }
2197 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2198 }
2199
2200 layermap=AbsoluteScr(map, screen+1)->layermap[1]-1;
2201
2202 if(layermap>-1 && layermap<map_count)
2203 {
2204 layerscreen=AbsoluteScr(map, screen+1)->layerscreen[1];
2205
2206 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2207 if (combobuf[cmbcheck2].type == cBRIDGE)
2208 {
2209 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2210 {
2211 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2212 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2213 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2214 }
2215 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2216 }
2217 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2218 }
2219
2220 if((combocheck1.walk&12)!=((combocheck2.walk&3)*4))
2221 {
2222 return true;
2223 }
2224
2225 break;
2226 }
2227 }
2228
2229 return false;
2230 }
2231
2232 void zmap::check_alignments(BITMAP* dest,int32_t x,int32_t y,int32_t scr)
2233 {
2234 int32_t checkcombo;
2235
2236 if(alignment_arrow_timer>31)
2237 {
2238 if(scr<0)
2239 {
2240 scr=cursor.screen;
2241 }
2242
2243 if((scr<128)) //do the misalignment arrows
2244 {
2245 for(checkcombo=1; checkcombo<15; checkcombo++) //check the top row (except the corners)
2246 {
2247 if(misaligned(cursor.map, scr, checkcombo, up))
2248 {
2249 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2250 }
2251 }
2252
2253 for(checkcombo=161; checkcombo<175; checkcombo++) //check the top row (except the corners)
2254 {
2255 if(misaligned(cursor.map, scr, checkcombo, down))
2256 {
2257 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2258 }
2259 }
2260
2261 for(checkcombo=16; checkcombo<160; checkcombo+=16) //check the left side (except the corners)
2262 {
2263 if(misaligned(cursor.map, scr, checkcombo, left))
2264 {
2265 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2266 }
2267 }
2268
2269 for(checkcombo=31; checkcombo<175; checkcombo+=16) //check the right side (except the corners)
2270 {
2271 if(misaligned(cursor.map, scr, checkcombo, right))
2272 {
2273 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2274 }
2275 }
2276
2277 int32_t tempalign;
2278
2279 //check top left corner
2280 checkcombo=0;
2281 tempalign=0;
2282 tempalign+=(misaligned(cursor.map, scr, checkcombo, up))?1:0;
2283 tempalign+=(misaligned(cursor.map, scr, checkcombo, left))?2:0;
2284
2285 switch(tempalign)
2286 {
2287 case 0:
2288 break;
2289
2290 case 1: //up
2291 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2292 break;
2293
2294 case 2: //left
2295 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2296 break;
2297
2298 case 3: //up-left
2299 masked_blit(arrow_bmp[4],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2300 break;
2301 }
2302
2303 //check top right corner
2304 checkcombo=15;
2305 tempalign=0;
2306 tempalign+=(misaligned(cursor.map, scr, checkcombo, up))?1:0;
2307 tempalign+=(misaligned(cursor.map, scr, checkcombo, right))?2:0;
2308
2309 switch(tempalign)
2310 {
2311 case 0:
2312 break;
2313
2314 case 1: //up
2315 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2316 break;
2317
2318 case 2: //right
2319 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2320 break;
2321
2322 case 3: //up-right
2323 masked_blit(arrow_bmp[5],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2324 break;
2325 }
2326
2327 //check bottom left corner
2328 checkcombo=160;
2329 tempalign=0;
2330 tempalign+=(misaligned(cursor.map, scr, checkcombo, down))?1:0;
2331 tempalign+=(misaligned(cursor.map, scr, checkcombo, left))?2:0;
2332
2333 switch(tempalign)
2334 {
2335 case 0:
2336 break;
2337
2338 case 1: //down
2339 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2340 break;
2341
2342 case 2: //left
2343 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2344 break;
2345
2346 case 3: //down-left
2347 masked_blit(arrow_bmp[6],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2348 break;
2349 }
2350
2351 //check bottom right corner
2352
2353 checkcombo=175;
2354 tempalign=0;
2355 tempalign+=(misaligned(cursor.map, scr, checkcombo, down))?1:0;
2356 tempalign+=(misaligned(cursor.map, scr, checkcombo, right))?2:0;
2357
2358 switch(tempalign)
2359 {
2360 case 0:
2361 break;
2362
2363 case 1: //down
2364 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2365 break;
2366
2367 case 2: //right
2368 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2369 break;
2370
2371 case 3: //down-right
2372 masked_blit(arrow_bmp[7],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2373 break;
2374 }
2375 }
2376 }
2377 }
2378
2379 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2380 {
2381 return MAPCOMBO3(map, screen, layer, COMBOPOS(x,y));
2382 }
2383
2384 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2385 {
2386 if (map < 0 || screen < 0) return 0;
2387
2388 if(pos>175 || pos < 0)
2389 return 0;
2390
2391 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2392
2393 if (!m->is_valid()) return 0;
2394
2395 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2396
2397 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2398
2399 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2400
2401 if (!scr->is_valid()) return 0;
2402
2403 return scr->data[pos]; // entire combo code
2404 }
2405
2406 // Takes array index layer num., not actual layer num.
2407 int32_t zmap::MAPCOMBO2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2408 {
2409 if(lyr<=-1) return MAPCOMBO(x,y,map,scr);
2410
2411 if(map<0)
2412 map=cursor.map;
2413
2414 if(scr<0)
2415 scr=cursor.screen;
2416
2417 mapscr *screen1;
2418
2419 if(prv_mode)
2420 {
2421 screen1=get_prvscr();
2422 }
2423 else
2424 {
2425 screen1=AbsoluteScr(cursor.map,cursor.screen);
2426 }
2427
2428 int32_t layermap;
2429 layermap=screen1->layermap[lyr]-1;
2430
2431 if(layermap<0 || layermap >= map_count) return 0;
2432
2433 mapscr *layer;
2434
2435 if(prv_mode)
2436 layer = &prvlayers[lyr];
2437 else
2438 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2439
2440 int32_t pos = COMBOPOS(x,y);
2441
2442 if(pos>175 || pos < 0)
2443 return 0;
2444
2445 return layer->data[pos];
2446 }
2447
2448 int32_t zmap::MAPCOMBO(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2449 {
2450 if(map<0)
2451 map=cursor.map;
2452
2453 if(scr<0)
2454 scr=cursor.screen;
2455
2456 mapscr *screen1;
2457
2458 if(prv_mode)
2459 {
2460 screen1=get_prvscr();
2461 }
2462 else
2463 {
2464 screen1=AbsoluteScr(cursor.map,cursor.screen);
2465 }
2466
2467 x = vbound(x, 0, 16*16);
2468 y = vbound(y, 0, 11*16);
2469 int32_t combo = COMBOPOS(x,y);
2470
2471 if(combo>175 || combo < 0)
2472 return 0;
2473
2474 return screen1->data[combo];
2475 }
2476
2477 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2478 {
2479 return MAPFLAG3(map, screen, layer, COMBOPOS(x,y));
2480 }
2481
2482 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2483 {
2484 if (map < 0 || screen < 0) return 0;
2485
2486 if(pos>175 || pos < 0)
2487 return 0;
2488
2489 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2490
2491 if (!m->is_valid()) return 0;
2492
2493 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2494
2495 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2496
2497 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2498
2499 if (!scr->is_valid()) return 0;
2500
2501 return scr->sflag[pos]; // entire combo code
2502 }
2503
2504 int32_t zmap::MAPFLAG2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2505 {
2506 if(lyr<=-1) return MAPFLAG(x,y,map,scr);
2507
2508 if(map<0)
2509 map=cursor.map;
2510
2511 if(scr<0)
2512 scr=cursor.screen;
2513
2514 mapscr *screen1;
2515
2516 if(prv_mode)
2517 {
2518 screen1=get_prvscr();
2519 }
2520 else
2521 {
2522 screen1=AbsoluteScr(cursor.map,cursor.screen);
2523 }
2524
2525 int32_t layermap;
2526 layermap=screen1->layermap[lyr]-1;
2527
2528 if(layermap<0 || layermap >= map_count) return 0;
2529
2530 mapscr *layer;
2531
2532 if(prv_mode)
2533 layer = &prvlayers[lyr];
2534 else
2535 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2536
2537 int32_t combo = COMBOPOS(x,y);
2538
2539 if(combo>175 || combo < 0)
2540 return 0;
2541
2542 return layer->sflag[combo];
2543 }
2544
2545 int32_t zmap::MAPFLAG(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2546 {
2547 if(map<0)
2548 map=cursor.map;
2549
2550 if(scr<0)
2551 scr=cursor.screen;
2552
2553 mapscr *screen1;
2554
2555 if(prv_mode)
2556 {
2557 screen1=get_prvscr();
2558 }
2559 else
2560 {
2561 screen1=AbsoluteScr(cursor.map,cursor.screen);
2562 }
2563
2564 x = vbound(x, 0, 16*16);
2565 y = vbound(y, 0, 11*16);
2566 int32_t combo = COMBOPOS(x,y);
2567
2568 if(combo>175 || combo < 0)
2569 return 0;
2570
2571 return screen1->sflag[combo];
2572 }
2573
2574 void zmap::draw_darkness(BITMAP* dest, BITMAP* transdest)
2575 {
2576 mapscr *layers[7];
2577 mapscr *basescr;
2578 if(prv_mode)
2579 {
2580 layers[0] = &prvscr;
2581 basescr = layers[0];
2582 for(auto q = 1; q < 7; ++q)
2583 {
2584 if(prvlayers[q-1].valid)
2585 layers[q] = &(prvlayers[q-1]);
2586 else layers[q] = NULL;
2587 }
2588 }
2589 else
2590 {
2591 layers[0] = AbsoluteScr(cursor.map, cursor.screen);
2592 basescr = layers[0];
2593 for(auto q = 1; q < 7; ++q)
2594 {
2595 int32_t lmap = basescr->layermap[q-1]-1;
2596 int32_t lscr = basescr->layerscreen[q-1];
2597 if(lmap < 0)
2598 layers[q] = NULL;
2599 else layers[q] = AbsoluteScr(lmap, lscr);
2600 }
2601 }
2602 for(auto q = 0; q < 7; ++q)
2603 {
2604 if(!layers[q]) continue;
2605 for(auto pos = 0; pos < 176; ++pos)
2606 {
2607 newcombo const& cmb = combobuf[layers[q]->data[pos]];
2608 if(cmb.type == cTORCH)
2609 do_torch_combo(cmb, COMBOX(pos)+8, COMBOY(pos)+8, dest, transdest);
2610 }
2611 }
2612 word maxffc = basescr->numFFC();
2613 for(auto q = 0; q < maxffc; ++q)
2614 {
2615 newcombo const& cmb = combobuf[basescr->ffcs[q].data];
2616 if(cmb.type == cTORCH)
2617 do_torch_combo(cmb, (basescr->ffcs[q].x.getInt())+(basescr->ffEffectWidth(q)/2), (basescr->ffcs[q].y.getInt())+(basescr->ffEffectHeight(q)/2), dest, transdest);
2618 }
2619 }
2620
2621 void drawcombo(BITMAP* dest, int32_t x, int32_t y, int32_t cid, int32_t cset, int32_t flags,
2622 int32_t sflag, bool over = true, bool transp = false, bool dither = false)
2623 {
2624 newcombo const& cmb = combobuf[cid];
2625 if(cmb.animflags & AF_TRANSPARENT) transp = !transp;
2626 if(dither)
2627 {
2628 if (LayerDitherSz == 0)
2629 return;
2630 BITMAP* buf = create_bitmap_ex(8,16,16);
2631 clear_bitmap(buf);
2632 overcombo(buf,0,0,cid,cset);
2633 ditherblit(buf,nullptr,0,dithChecker,LayerDitherSz,x,y);
2634 if(over)
2635 {
2636 if(transp)
2637 {
2638 color_map = trans_table2;
2639 draw_trans_sprite(dest, buf, x, y);
2640 color_map = trans_table;
2641 }
2642 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2643 }
2644 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2645 destroy_bitmap(buf);
2646 }
2647 else if(over)
2648 {
2649 if(transp)
2650 overcombotranslucent(dest,x,y,cid,cset,0);
2651 else overcombo(dest,x,y,cid,cset);
2652 }
2653 else put_combo(dest,x,y,cid,cset,flags,sflag);
2654 }
2655 static void _zmap_drawlayer(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool over, bool dither, bool passflag = false)
2656 {
2657 if(!md) return;
2658 for (int32_t i = 0; i < 176; i++)
2659 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, md->data[i], md->cset[i], flags, passflag ? md->sflag[i] : 0, over, trans, dither);
2660 }
2661 static void _zmap_drawlayer_ohead(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool dither)
2662 {
2663 if(!md) return;
2664 for (int32_t i = 0; i < 176; i++)
2665 {
2666 int data = md->data[i];
2667 if(combo_class_buf[combobuf[data].type].overhead)
2668 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, data, md->cset[i], 0, 0, true, trans, dither);
2669 }
2670 }
2671 static mapscr* _zmap_get_lyr_checked(int lyr, mapscr* basescr)
2672 {
2673 if(!LayerMaskInt[lyr])
2674 return nullptr;
2675 if(lyr == 0)
2676 return basescr;
2677 int layermap = basescr->layermap[lyr-1]-1;
2678
2679 if(layermap>-1 && layermap<map_count)
2680 {
2681 int layerscreen = layermap*MAPSCRS+basescr->layerscreen[lyr-1];
2682 return &TheMaps[layerscreen];
2683 }
2684 return nullptr;
2685 }
2686 static void _zmap_draw_ffc_layer(BITMAP* dest,int32_t x,int32_t y,int32_t flags,mapscr* basescr, int32_t layer)
2687 {
2688 int num_ffcs = basescr->numFFC();
2689 for(int32_t i=num_ffcs-1; i>=0; i--)
2690 {
2691 auto const& ff = basescr->ffcs[i];
2692 if(ff.data)
2693 {
2694 if(!(ff.flags&ffc_changer))
2695 {
2696 int32_t tx=(ff.x.getInt())+x;
2697 int32_t ty=(ff.y.getInt())+y;
2698
2699 if((ff.flags&ffc_overlay) ? layer == -1 : layer == ff.layer)
2700 {
2701 if(ff.flags&ffc_trans)
2702 overcomboblocktranslucent(dest,tx,ty,ff.data, ff.cset, ff.txsz, ff.tysz,128);
2703 else
2704 overcomboblock(dest, tx, ty, ff.data, ff.cset, ff.txsz, ff.tysz);
2705 }
2706 }
2707 }
2708 }
2709 }
2710 void zmap::draw(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t map,int32_t screen,int32_t hl_layer)
2711 {
2712 #define HL_LAYER(lyr) (!(NoHighlightLayer0 && hl_layer == 0) && hl_layer > -1 && hl_layer != lyr)
2713 int32_t antiflags=(flags&~cFLAGS)&~cWALK;
2714 bool olddraw = get_qr(qr_CLASSIC_DRAWING_ORDER);
2715
2716 if(map<0)
2717 map=cursor.map;
2718
2719 if(screen<0)
2720 screen=cursor.screen;
2721
2722 mapscr *basescr;
2723 mapscr* layers[7] = {nullptr};
2724
2725 if(prv_mode)
2726 {
2727 hl_layer = -1;
2728 basescr=get_prvscr();
2729 }
2730 else
2731 {
2732 basescr=AbsoluteScr(map,screen);
2733 }
2734 layers[0] = _zmap_get_lyr_checked(0,basescr);
2735 for(int lyr = 1; lyr < 7; ++lyr)
2736 {
2737 layers[lyr] = prv_mode ? ((&prvlayers[lyr-1])->valid ? &prvlayers[lyr - 1] : nullptr)
2738 : _zmap_get_lyr_checked(lyr,basescr);
2739 }
2740
2741 if(!(basescr->valid&mVALID))
2742 {
2743 // rectfill(dest,x,y,x+255,y+175,dvc(0+1));
2744 rectfill(dest,x,y,x+255,y+175,vc(1));
2745
2746 if(ShowMisalignments)
2747 {
2748 check_alignments(dest,x,y,screen);
2749 }
2750
2751 return;
2752 }
2753
2754 if(LayerMaskInt[0]==0 || !get_qr(qr_CLASSIC_DRAWING_ORDER))
2755 {
2756 byte bgfill = 0;
2757 if (LayerDitherBG > -1)
2758 bgfill = vc(LayerDitherBG);
2759 rectfill(dest,x,y,x+255,y+175,bgfill);
2760 }
2761
2762 if(olddraw)
2763 {
2764 if(XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2765 _zmap_drawlayer(dest, x, y, layers[2], antiflags, false, false, HL_LAYER(2));
2766 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -2);
2767 }
2768 else for (int lyr = -7; lyr < -3; ++lyr)
2769 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, lyr);
2770
2771 if(XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2772 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG), HL_LAYER(3));
2773 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -3);
2774
2775 if(!olddraw)
2776 {
2777 if(XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2778 _zmap_drawlayer(dest, x, y, layers[2], antiflags, false, true, HL_LAYER(2));
2779 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -2);
2780 }
2781 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -1);
2782
2783 _zmap_drawlayer(dest, x, y, layers[0], antiflags, false, !olddraw || (XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG)||XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG)), HL_LAYER(0), true);
2784 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 0);
2785
2786
2787 _zmap_drawlayer(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, true, HL_LAYER(1));
2788 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 1);
2789
2790 if(!XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2791 _zmap_drawlayer(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, true, HL_LAYER(2));
2792 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 2);
2793
2794 struct DoorDrawData
2795 {
2796 int over_pos; // Position for over_door (dBOMB)
2797 int put_pos; // Position for put_door (standard doors)
2798 int walk_x; // Pre-calculated X offset for dWALK
2799 int walk_y; // Pre-calculated Y offset for dWALK
2800 };
2801
2802 static const DoorDrawData door_data[4] = {
2803 // over, put, walk_x, walk_y
2804 { 39, 7, 120, 16 }, // up
2805 { 135, 151, 120, 144 }, // down
2806 { 66, 64, 16, 80 }, // left
2807 { 77, 78, 224, 80 } // right
2808 };
2809
2810 auto door_set = DoorComboSets[screens[cursor.screen].door_combo_set];
2811 bool walk_trans = get_bit(door_set.flags, df_walktrans);
2812
2813 int32_t doortype[4];
2814 for(int32_t i=0; i<4; i++)
2815 {
2816 switch(basescr->door[i])
2817 {
2818 case dOPEN: doortype[i]=dt_pass; break;
2819 case dLOCKED: doortype[i]=dt_lock; break;
2820 case d1WAYSHUTTER:
2821 case dSHUTTER: doortype[i]=dt_shut; break;
2822 case dBOSS: doortype[i]=dt_boss; break;
2823 case dBOMB: doortype[i]=dt_bomb; break;
2824 default: doortype[i]=0; // Default or unhandled
2825 }
2826 }
2827
2828 for (int i = 0; i < 4; ++i)
2829 {
2830 const auto& d = door_data[i];
2831 const int current_door_type_id = basescr->door[i];
2832
2833 switch (current_door_type_id) {
2834 case dBOMB:
2835 // Draw bombable overlay, then fall through to draw the door
2836 over_door(dest, d.over_pos, i, x, y, false, screen);
2837 [[fallthrough]];
2838
2839 case dOPEN:
2840 case dLOCKED:
2841 case d1WAYSHUTTER:
2842 case dSHUTTER:
2843 case dBOSS:
2844 {
2845 put_door(dest, d.put_pos, i, doortype[i], x, y, false, screen);
2846 break;
2847 }
2848
2849 case dWALK:
2850 if (walk_trans) {
2851 overcombo(dest, d.walk_x + x, d.walk_y + y,
2852 door_set.walkthroughcombo[i],
2853 door_set.walkthroughcset[i]);
2854 } else {
2855 put_combo(dest, d.walk_x + x, d.walk_y + y,
2856 door_set.walkthroughcombo[i],
2857 door_set.walkthroughcset[i], 0, 0);
2858 }
2859 break;
2860 }
2861 }
2862
2863 if((basescr->hasitem != 0) && !(flags&cNOITEM))
2864 {
2865 putitem2(dest,basescr->itemx+x,basescr->itemy+y+1-(get_qr(qr_NOITEMOFFSET)),basescr->item,lens_hint_item[basescr->item][0],lens_hint_item[basescr->item][1], 0);
2866 }
2867
2868 if(!XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2869 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, true, HL_LAYER(3));
2870 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 3);
2871
2872 _zmap_drawlayer(dest, x, y, layers[4], antiflags, basescr->layeropacity[4-1]!=255, true, HL_LAYER(4));
2873 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 4);
2874
2875 _zmap_drawlayer_ohead(dest, x, y, layers[0], antiflags, false, HL_LAYER(0));
2876
2877 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
2878 {
2879 _zmap_drawlayer_ohead(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, HL_LAYER(1));
2880 _zmap_drawlayer_ohead(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, HL_LAYER(2));
2881 }
2882 _zmap_drawlayer(dest, x, y, layers[5], antiflags, basescr->layeropacity[5-1]!=255, true, HL_LAYER(5));
2883 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 5);
2884
2885 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -1);
2886
2887 _zmap_drawlayer(dest, x, y, layers[6], antiflags, basescr->layeropacity[6-1]!=255, true, HL_LAYER(6));
2888 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 6);
2889 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 7);
2890
2891 int num_ffcs = basescr->numFFC();
2892 for(int32_t i=num_ffcs-1; i>=0; i--) // changer ffcs
2893 if(basescr->ffcs[i].data)
2894 if(basescr->ffcs[i].flags&ffc_changer)
2895 putpixel(dest,(basescr->ffcs[i].x.getInt())+x,(basescr->ffcs[i].y.getInt())+y,vc(zc_oldrand()%16));
2896
2897 if(flags&cWALK)
2898 {
2899 if(layers[0])
2900 for(int32_t i=0; i<176; i++)
2901 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[0]->data[i], 0);
2902
2903 for(int32_t k=0; k<2; k++)
2904 {
2905 if(layers[k+1])
2906 for(int32_t i=0; i<176; i++)
2907 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[k+1]->data[i], 0);
2908 }
2909 for(int32_t i=num_ffcs-1; i>=0; i--)
2910 {
2911 if(auto data = basescr->ffcs[i].data)
2912 {
2913 if(!(basescr->ffcs[i].flags&ffc_changer))
2914 {
2915 newcombo const& cmb = combobuf[data];
2916 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2917 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2918
2919 if(basescr->ffcs[i].flags&ffc_solid)
2920 {
2921 rectfill(dest, tx, ty, tx + basescr->ffEffectWidth(i) - 1, ty + basescr->ffEffectHeight(i) - 1, COLOR_SOLID);
2922 }
2923
2924 if(cmb.type == cSLOPE)
2925 {
2926 slope_info s(cmb, tx, ty);
2927 s.draw(dest, 0, 0, COLOR_SLOPE);
2928 }
2929 }
2930 }
2931 }
2932 }
2933
2934 if(flags&cFLAGS)
2935 {
2936 if(LayerMaskInt[CurrentLayer]!=0)
2937 {
2938 int32_t _lscr=(basescr->layermap[CurrentLayer-1]-1)*MAPSCRS+basescr->layerscreen[CurrentLayer-1];
2939 auto* scr = _lscr>-1 && _lscr<map_count*MAPSCRS ? &TheMaps[_lscr] : nullptr;
2940
2941 for(int32_t i=0; i<176; i++)
2942 {
2943 if(CurrentLayer==0)
2944 {
2945 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,basescr->data[i],basescr->cset[i],flags,basescr->sflag[i]);
2946 }
2947 else
2948 {
2949 if(prv_mode)
2950 {
2951 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,prvlayers[CurrentLayer-1].data[i],prvlayers[CurrentLayer-1].cset[i],flags,prvlayers[CurrentLayer-1].sflag[i]);
2952 }
2953 else if(basescr->layermap[CurrentLayer-1] > 0)
2954 {
2955 if(scr)
2956 {
2957 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,
2958 scr->data[i],
2959 scr->cset[i], flags,
2960 scr->sflag[i]);
2961 }
2962 }
2963 }
2964 }
2965 }
2966 }
2967
2968 int32_t dark = basescr->flags&cDARK;
2969
2970 if(dark && !(flags&cNODARK)
2971 && !((Flags&cNEWDARK) && get_qr(qr_NEW_DARKROOM)))
2972 {
2973 int col = vc(blackout_color);
2974 for(int32_t j=0; j<80; j++) {
2975 // Logic: ((i^j)&1)==0 means parity matches
2976 int start = (j&1);
2977 for(int32_t i=start; i<(80)-j; i+=2) {
2978 putpixel(dest,x+i,y+j,col);
2979 }
2980 }
2981 }
2982
2983 if(ShowMisalignments)
2984 {
2985 check_alignments(dest,x,y,screen);
2986 }
2987 }
2988
2989 void zmap::drawrow(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
2990 {
2991 if(map<0)
2992 map=cursor.map;
2993
2994 if(scr<0)
2995 scr=cursor.screen;
2996
2997 mapscr* layer=AbsoluteScr(map,scr);
2998 int32_t layermap=0, layerscreen=0;
2999
3000 if(!(layer->valid&mVALID))
3001 {
3002 // rectfill(dest,x,y,x+255,y+15,dvc(0+1));
3003 rectfill(dest,x,y,x+255,y+15,vc(1));
3004 return;
3005 }
3006
3007 int32_t dark = layer->flags&4;
3008
3009 if(LayerMaskInt[0]==0)
3010 {
3011 rectfill(dest,x,y,x+255,y+15,0);
3012 }
3013
3014 bool olddraw = get_qr(qr_CLASSIC_DRAWING_ORDER);
3015 int order[2] = {2,1};
3016 if (olddraw) zc_swap(order[0],order[1]);
3017 for(int k : order)
3018 {
3019 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3020 {
3021 layermap=layer->layermap[k]-1;
3022
3023 if(layermap>-1 && layermap<map_count)
3024 {
3025 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3026
3027 for(int32_t i=c; i<(c&0xF0)+16; i++)
3028 {
3029 auto data = TheMaps[layerscreen].data[i];
3030 auto cs = TheMaps[layerscreen].cset[i];
3031 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3032 }
3033 }
3034 }
3035 }
3036
3037 if(LayerMaskInt[0]!=0)
3038 {
3039 for(int32_t i=c; i<(c&0xF0)+16; i++)
3040 {
3041 word cmbdat = (i < 176 ? layer->data[i] : 0);
3042 byte cmbcset = (i < 176 ? layer->cset[i] : 0);
3043 int32_t cmbflag = (i < 176 ? layer->sflag[i] : 0);
3044 drawcombo(dest,((i&15)<<4)+x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),
3045 cmbflag,!olddraw || (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3046 }
3047 }
3048
3049 for(int32_t k=0; k<2; k++)
3050 {
3051 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3052 {
3053 layermap=layer->layermap[k]-1;
3054
3055 if(layermap>-1 && layermap<map_count)
3056 {
3057 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3058
3059 for(int32_t i=c; i<(c&0xF0)+16; i++)
3060 {
3061 auto data = TheMaps[layerscreen].data[i];
3062 auto cs = TheMaps[layerscreen].cset[i];
3063 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3064 }
3065 }
3066 }
3067 }
3068
3069 int32_t doortype[4];
3070
3071 for(int32_t i=0; i<4; i++)
3072 {
3073 switch(layer->door[i])
3074 {
3075 case dOPEN:
3076 doortype[i]=dt_pass;
3077 break;
3078
3079 case dLOCKED:
3080 doortype[i]=dt_lock;
3081 break;
3082
3083 case d1WAYSHUTTER:
3084 case dSHUTTER:
3085 doortype[i]=dt_shut;
3086 break;
3087
3088 case dBOSS:
3089 doortype[i]=dt_boss;
3090 break;
3091
3092 case dBOMB:
3093 doortype[i]=dt_bomb;
3094 break;
3095 }
3096 }
3097
3098 if(c<16)
3099 {
3100 switch(layer->door[up])
3101 {
3102 case dBOMB:
3103 case dOPEN:
3104 case dLOCKED:
3105 case d1WAYSHUTTER:
3106 case dSHUTTER:
3107 case dBOSS:
3108 put_door(dest,7,up,doortype[up],x,y+176,true,scr);
3109 break;
3110 }
3111 }
3112 else if(c>159)
3113 {
3114 switch(layer->door[down])
3115 {
3116 case dBOMB:
3117 case dOPEN:
3118 case dLOCKED:
3119 case d1WAYSHUTTER:
3120 case dSHUTTER:
3121 case dBOSS:
3122 put_door(dest,151,down,doortype[down],x,y-16,true,scr);
3123 break;
3124 }
3125 }
3126
3127 for(int32_t k=2; k<4; k++)
3128 {
3129 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3130 {
3131 layermap=layer->layermap[k]-1;
3132
3133 if(layermap>-1 && layermap<map_count)
3134 {
3135 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3136
3137 for(int32_t i=c; i<(c&0xF0)+16; i++)
3138 {
3139 if(layer->layeropacity[k]<255)
3140 {
3141 overcombotranslucent(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i],layer->layeropacity[k]);
3142 }
3143 else
3144 {
3145 overcombo(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i]);
3146 }
3147 }
3148 }
3149 }
3150 }
3151
3152 //Overhead L0
3153 if(LayerMaskInt[0]!=0)
3154 {
3155 for(int32_t i=c; i<(c&0xF0)+16; i++)
3156 {
3157 int32_t ct1=layer->data[i];
3158 int32_t ct3=combobuf[ct1].type;
3159
3160 if(combo_class_buf[ct3].overhead)
3161 {
3162 drawcombo(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],0,0);
3163 }
3164 }
3165 }
3166
3167 //Overhead L1/2
3168 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3169 {
3170 for(int32_t k = 0; k < 2; ++k)
3171 {
3172 if(LayerMaskInt[k+1]!=0)
3173 {
3174 layermap=layer->layermap[k]-1;
3175
3176 if(layermap>-1 && layermap<map_count)
3177 {
3178 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3179 for(int32_t i=c; i<(c&0xF0)+16; i++)
3180 {
3181 auto data = TheMaps[layerscreen].data[i];
3182 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3183 auto cs = TheMaps[layerscreen].cset[i];
3184 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3185 }
3186 }
3187 }
3188 }
3189 }
3190
3191 for(int32_t k=4; k<6; k++)
3192 {
3193 if(LayerMaskInt[k+1]!=0)
3194 {
3195 layermap=layer->layermap[k]-1;
3196
3197 if(layermap>-1 && layermap<map_count)
3198 {
3199 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3200
3201 for(int32_t i=c; i<(c&0xF0)+16; i++)
3202 {
3203 auto data = TheMaps[layerscreen].data[i];
3204 auto cs = TheMaps[layerscreen].cset[i];
3205 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3206 }
3207 }
3208 }
3209 }
3210
3211 if(flags&cWALK)
3212 {
3213 if(LayerMaskInt[0]!=0)
3214 {
3215 for(int32_t i=c; i<(c&0xF0)+16; i++)
3216 {
3217 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, -1, map,scr);
3218 }
3219 }
3220
3221 for(int32_t k=0; k<2; k++)
3222 {
3223 if(LayerMaskInt[k+1]!=0)
3224 {
3225 for(int32_t i=c; i<(c&0xF0)+16; i++)
3226 {
3227 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, k, map,scr);
3228 }
3229 }
3230 }
3231 }
3232
3233 if(flags&cFLAGS)
3234 {
3235 if(LayerMaskInt[CurrentLayer]!=0)
3236 {
3237 for(int32_t i=c; i<(c&0xF0)+16; i++)
3238 {
3239 if(CurrentLayer==0)
3240 {
3241 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3242 }
3243 else
3244 {
3245 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3246
3247 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3248 {
3249 if(i < 176)
3250 {
3251 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,
3252 TheMaps[_lscr].data[i],
3253 TheMaps[_lscr].cset[i], flags|dark,
3254 TheMaps[_lscr].sflag[i]);
3255 }
3256 else
3257 {
3258 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,0,0, flags|dark,0);
3259 }
3260 }
3261 }
3262 }
3263 }
3264
3265 /*
3266 if (LayerMaskInt[0]!=0) {
3267 for(int32_t i=c; i<(c&0xF0)+16; i++) {
3268 put_flags(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3269 }
3270 }
3271 */
3272 }
3273
3274 if(ShowMisalignments)
3275 {
3276 if(c<16)
3277 {
3278 check_alignments(dest,x,y,scr);
3279 }
3280 else if(c>159)
3281 {
3282 check_alignments(dest,x,y-160,scr);
3283 }
3284 }
3285 }
3286
3287 void zmap::drawcolumn(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3288 {
3289 if(map<0)
3290 map=cursor.map;
3291
3292 if(scr<0)
3293 scr=cursor.screen;
3294
3295 mapscr* layer=AbsoluteScr(map,scr);
3296 int32_t layermap=0, layerscreen=0;
3297
3298 if(!(layer->valid&mVALID))
3299 {
3300 // rectfill(dest,x,y,x+15,y+175,dvc(0+1));
3301 rectfill(dest,x,y,x+15,y+175,vc(1));
3302 return;
3303 }
3304
3305 int32_t dark = layer->flags&4;
3306
3307 if(LayerMaskInt[0]==0)
3308 {
3309 rectfill(dest,x,y,x+15,y+175,0);
3310 }
3311
3312 bool olddraw = get_qr(qr_CLASSIC_DRAWING_ORDER);
3313 int order[2] = {2,1};
3314 if (olddraw) zc_swap(order[0],order[1]);
3315 for(int k : order)
3316 {
3317 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3318 {
3319 layermap=layer->layermap[k]-1;
3320
3321 if(layermap>-1 && layermap<map_count)
3322 {
3323 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3324
3325 for(int32_t i=c; i<176; i+=16)
3326 {
3327 auto data = TheMaps[layerscreen].data[i];
3328 auto cs = TheMaps[layerscreen].cset[i];
3329 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3330 }
3331 }
3332 }
3333 }
3334
3335 if(LayerMaskInt[0]!=0)
3336 {
3337 for(int32_t i=c; i<176; i+=16)
3338 {
3339 word cmbdat = layer->data[i];
3340 byte cmbcset = layer->cset[i];
3341 int32_t cmbflag = layer->sflag[i];
3342 drawcombo(dest,x,(i&0xF0)+y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3343 !olddraw || (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3344 }
3345 }
3346
3347 for(int32_t k=0; k<2; k++)
3348 {
3349 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3350 {
3351 layermap=layer->layermap[k]-1;
3352
3353 if(layermap>-1 && layermap<map_count)
3354 {
3355 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3356
3357 for(int32_t i=c; i<176; i+=16)
3358 {
3359 auto data = TheMaps[layerscreen].data[i];
3360 auto cs = TheMaps[layerscreen].cset[i];
3361 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3362 }
3363 }
3364 }
3365 }
3366
3367 int32_t doortype[4];
3368
3369 for(int32_t i=0; i<4; i++)
3370 {
3371 switch(layer->door[i])
3372 {
3373 case dOPEN:
3374 doortype[i]=dt_pass;
3375 break;
3376
3377 case dLOCKED:
3378 doortype[i]=dt_lock;
3379 break;
3380
3381 case d1WAYSHUTTER:
3382 case dSHUTTER:
3383 doortype[i]=dt_shut;
3384 break;
3385
3386 case dBOSS:
3387 doortype[i]=dt_boss;
3388 break;
3389
3390 case dBOMB:
3391 doortype[i]=dt_bomb;
3392 break;
3393 }
3394 }
3395
3396 if((c&0x0F)==0)
3397 {
3398 switch(layer->door[left])
3399 {
3400
3401 case dBOMB:
3402 case dOPEN:
3403 case dLOCKED:
3404 case d1WAYSHUTTER:
3405 case dSHUTTER:
3406 case dBOSS:
3407 // put_door(dest,64,left,doortype[left],x+256,y,true);
3408 put_door(dest,64,left,doortype[left],x,y,true,scr);
3409 break;
3410 }
3411 }
3412 else if((c&0x0F)==15)
3413 {
3414 switch(layer->door[right])
3415 {
3416 case dBOMB:
3417 case dOPEN:
3418 case dLOCKED:
3419 case d1WAYSHUTTER:
3420 case dSHUTTER:
3421 case dBOSS:
3422 put_door(dest,78,right,doortype[right],x-16,y,true,scr);
3423 break;
3424 }
3425 }
3426
3427 for(int32_t k=2; k<4; k++)
3428 {
3429 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3430 {
3431 layermap=layer->layermap[k]-1;
3432
3433 if(layermap>-1 && layermap<map_count)
3434 {
3435 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3436
3437 for(int32_t i=c; i<176; i+=16)
3438 {
3439 auto data = TheMaps[layerscreen].data[i];
3440 auto cs = TheMaps[layerscreen].cset[i];
3441 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3442 }
3443 }
3444 }
3445 }
3446
3447 //Overhead L0
3448 if(LayerMaskInt[0]!=0)
3449 {
3450 for(int32_t i=c; i<176; i+=16)
3451 {
3452 auto data = TheMaps[layerscreen].data[i];
3453 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3454 auto cs = TheMaps[layerscreen].cset[i];
3455 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0);
3456 }
3457 }
3458 //Overhead L1/2
3459 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3460 {
3461 for(int32_t k = 0; k < 2; ++k)
3462 {
3463 if(LayerMaskInt[k+1]!=0)
3464 {
3465 layermap=layer->layermap[k]-1;
3466
3467 if(layermap>-1 && layermap<map_count)
3468 {
3469 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3470 for(int32_t i=c; i<176; i+=16)
3471 {
3472 auto data = TheMaps[layerscreen].data[i];
3473 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3474 auto cs = TheMaps[layerscreen].cset[i];
3475 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3476 }
3477 }
3478 }
3479 }
3480 }
3481
3482
3483 for(int32_t k=4; k<6; k++)
3484 {
3485 if(LayerMaskInt[k+1]!=0)
3486 {
3487 layermap=layer->layermap[k]-1;
3488
3489 if(layermap>-1 && layermap<map_count)
3490 {
3491 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3492
3493 for(int32_t i=c; i<176; i+=16)
3494 {
3495 auto data = TheMaps[layerscreen].data[i];
3496 auto cs = TheMaps[layerscreen].cset[i];
3497 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3498 }
3499 }
3500 }
3501 }
3502
3503 if(flags&cWALK)
3504 {
3505 if(LayerMaskInt[0]!=0)
3506 {
3507 for(int32_t i=c&0xF; i<176; i+=16)
3508 {
3509 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, -1, map,scr);
3510 }
3511 }
3512
3513 for(int32_t k=0; k<2; k++)
3514 {
3515 if(LayerMaskInt[k+1]!=0)
3516 {
3517 for(int32_t i=c&0xF; i<176; i+=16)
3518 {
3519 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, k, map,scr);
3520 }
3521 }
3522 }
3523 }
3524
3525 if(flags&cFLAGS)
3526 {
3527 if(LayerMaskInt[CurrentLayer]!=0)
3528 {
3529 for(int32_t i=c; i<176; i+=16)
3530 {
3531 if(CurrentLayer==0)
3532 {
3533 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3534 }
3535 else
3536 {
3537 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3538
3539 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3540 {
3541 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,
3542 TheMaps[_lscr].data[i],
3543 TheMaps[_lscr].cset[i], flags|dark,
3544 TheMaps[_lscr].sflag[i]);
3545 }
3546 }
3547 }
3548 }
3549 }
3550
3551 if(ShowMisalignments)
3552 {
3553 if((c&0x0F)==0)
3554 {
3555 check_alignments(dest,x,y,scr);
3556 }
3557 else if((c&0x0F)==15)
3558 {
3559 check_alignments(dest,x-240,y,scr);
3560 }
3561 }
3562 }
3563
3564 void zmap::drawblock(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3565 {
3566 if(map<0)
3567 map=cursor.map;
3568
3569 if(scr<0)
3570 scr=cursor.screen;
3571
3572 mapscr* layer=AbsoluteScr(map,scr);
3573 int32_t layermap=0, layerscreen=0;
3574
3575 if(!(layer->valid&mVALID))
3576 {
3577 // rectfill(dest,x,y,x+15,y+15,dvc(0+1));
3578 rectfill(dest,x,y,x+15,y+15,vc(1));
3579 return;
3580 }
3581
3582 int32_t dark = layer->flags&4;
3583
3584 if(LayerMaskInt[0]!=0)
3585 {
3586 rectfill(dest,x,y,x+15,y+15,0);
3587 }
3588
3589 bool olddraw = get_qr(qr_CLASSIC_DRAWING_ORDER);
3590 int order[2] = {2,1};
3591 if (olddraw) zc_swap(order[0],order[1]);
3592 for(int k : order)
3593 {
3594 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3595 {
3596 layermap=layer->layermap[k]-1;
3597
3598 if(layermap>-1 && layermap<map_count)
3599 {
3600 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3601
3602 auto data = TheMaps[layerscreen].data[c];
3603 auto cs = TheMaps[layerscreen].cset[c];
3604 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3605 }
3606 }
3607 }
3608
3609 if(LayerMaskInt[0]!=0)
3610 {
3611 word cmbdat = layer->data[c];
3612 byte cmbcset = layer->cset[c];
3613 int32_t cmbflag = layer->sflag[c];
3614 drawcombo(dest,x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3615 !olddraw || (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3616 }
3617
3618
3619 for(int32_t k=0; k<2; k++)
3620 {
3621 if(LayerMaskInt[k+1]!=0)
3622 {
3623 layermap=layer->layermap[k]-1;
3624
3625 if(layermap>-1 && layermap<map_count)
3626 {
3627 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3628
3629 auto data = TheMaps[layerscreen].data[c];
3630 auto cs = TheMaps[layerscreen].cset[c];
3631 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3632 }
3633 }
3634 }
3635
3636 for(int32_t k=2; k<4; k++)
3637 {
3638 if(LayerMaskInt[k+1]!=0)
3639 {
3640 layermap=layer->layermap[k]-1;
3641
3642 if(layermap>-1 && layermap<map_count)
3643 {
3644 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3645 auto data = TheMaps[layerscreen].data[c];
3646 auto cs = TheMaps[layerscreen].cset[c];
3647 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3648 }
3649 }
3650 }
3651
3652 //Overhead L0
3653 if(LayerMaskInt[0]!=0)
3654 {
3655 auto data = TheMaps[layerscreen].data[c];
3656 if(combo_class_buf[combobuf[data].type].overhead)
3657 {
3658 auto cs = TheMaps[layerscreen].cset[c];
3659 drawcombo(dest,x,y,data,cs,0,0);
3660 }
3661 }
3662 //Overhead L1/2
3663 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3664 {
3665 for(int32_t k = 0; k < 2; ++k)
3666 {
3667 if(LayerMaskInt[k+1]!=0)
3668 {
3669 layermap=layer->layermap[k]-1;
3670
3671 if(layermap>-1 && layermap<map_count)
3672 {
3673 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3674 auto data = TheMaps[layerscreen].data[c];
3675 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3676 auto cs = TheMaps[layerscreen].cset[c];
3677 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3678 }
3679 }
3680 }
3681 }
3682
3683
3684 for(int32_t k=4; k<6; k++)
3685 {
3686 if(LayerMaskInt[k+1]!=0)
3687 {
3688 layermap=layer->layermap[k]-1;
3689
3690 if(layermap>-1 && layermap<map_count)
3691 {
3692 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3693 auto data = TheMaps[layerscreen].data[c];
3694 auto cs = TheMaps[layerscreen].cset[c];
3695 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3696 }
3697 }
3698 }
3699
3700 if(flags&cWALK)
3701 {
3702 if(LayerMaskInt[0]!=0)
3703 {
3704 put_walkflags_layered_external(dest,x,y,c,-1, map,scr);
3705 }
3706
3707 for(int32_t k=0; k<2; k++)
3708 {
3709 if(LayerMaskInt[k+1]!=0)
3710 {
3711 put_walkflags_layered_external(dest,x,y,c,k, map,scr);
3712 }
3713 }
3714 }
3715
3716 if(flags&cFLAGS)
3717 {
3718 if(LayerMaskInt[CurrentLayer]!=0)
3719 {
3720 int32_t i = c;
3721 //for(int32_t i=c; i==c; i++)
3722 {
3723 if(CurrentLayer==0)
3724 {
3725 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3726 }
3727 else
3728 {
3729 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3730
3731 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3732 {
3733 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,
3734 TheMaps[_lscr].data[i],
3735 TheMaps[_lscr].cset[i], flags|dark,
3736 TheMaps[_lscr].sflag[i]);
3737 }
3738 }
3739 }
3740 }
3741 }
3742
3743 if(ShowMisalignments)
3744 {
3745 switch(c)
3746 {
3747 case 0:
3748 check_alignments(dest,x,y,scr);
3749 break;
3750
3751 case 15:
3752 check_alignments(dest,x-240,y,scr);
3753 break;
3754
3755 case 160:
3756 check_alignments(dest,x,y-160,scr);
3757 break;
3758
3759 case 175:
3760 check_alignments(dest,x-240,y-160,scr);
3761 break;
3762 }
3763 }
3764 }
3765
3766 void zmap::drawstaticblock(BITMAP* dest,int32_t x,int32_t y)
3767 {
3768 if (InvalidBG == 2)
3769 {
3770 draw_checkerboard(dest, x, y, 16);
3771 }
3772 else if(InvalidBG == 1)
3773 {
3774 for(int32_t dy=0; dy<16; dy++)
3775 {
3776 for(int32_t dx=0; dx<16; dx++)
3777 {
3778 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3779 }
3780 }
3781 }
3782 else
3783 {
3784 rectfill(dest, x, y, x+15, y+15, vc(0));
3785 rect(dest, x, y, x+15, y+15, vc(15));
3786 line(dest, x, y, x+15, y+15, vc(15));
3787 line(dest, x, y+15, x+15, y, vc(15));
3788 }
3789 }
3790
3791 void zmap::drawstaticcolumn(BITMAP* dest,int32_t x,int32_t y)
3792 {
3793 if (InvalidBG == 2)
3794 {
3795 for(int32_t q = 0; q < 11; ++q)
3796 draw_checkerboard(dest, x, y + q * 16, 16);
3797 }
3798 else if(InvalidBG == 1)
3799 {
3800 for(int32_t dy=0; dy<176; dy++)
3801 {
3802 for(int32_t dx=0; dx<16; dx++)
3803 {
3804 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3805 }
3806 }
3807 }
3808 else
3809 {
3810 rectfill(dest, x, y, x+15, y+175, vc(0));
3811 rect(dest, x, y, x+15, y+175, vc(15));
3812 line(dest, x, y, x+15, y+175, vc(15));
3813 line(dest, x, y+175, x+15, y, vc(15));
3814 }
3815 }
3816
3817 void zmap::drawstaticrow(BITMAP* dest,int32_t x,int32_t y)
3818 {
3819 if (InvalidBG == 2)
3820 {
3821 for (int32_t q = 0; q < 16; ++q)
3822 draw_checkerboard(dest, x + q * 16, y, 16);
3823 }
3824 else if(InvalidBG == 1)
3825 {
3826 for(int32_t dy=0; dy<16; dy++)
3827 {
3828 for(int32_t dx=0; dx<256; dx++)
3829 {
3830 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3831 }
3832 }
3833 }
3834 else
3835 {
3836 rectfill(dest, x, y, x+255, y+15, vc(0));
3837 rect(dest, x, y, x+255, y+15, vc(15));
3838 line(dest, x, y, x+255, y+15, vc(15));
3839 line(dest, x, y+15, x+255, y, vc(15));
3840 }
3841 }
3842
3843 void zmap::draw_template(BITMAP* dest,int32_t x,int32_t y)
3844 {
3845 for(int32_t i=0; i<176; i++)
3846 {
3847 word cmbdat = screens[TEMPLATE].data[i];
3848 byte cmbcset = screens[TEMPLATE].cset[i];
3849 int32_t cmbflag = screens[TEMPLATE].sflag[i];
3850 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3851 }
3852 }
3853
3854 void zmap::draw_template2(BITMAP* dest,int32_t x,int32_t y)
3855 {
3856 for(int32_t i=0; i<176; i++)
3857 {
3858 word cmbdat = screens[TEMPLATE2].data[i];
3859 byte cmbcset = screens[TEMPLATE2].cset[i];
3860 int32_t cmbflag = screens[TEMPLATE2].sflag[i];
3861 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3862 }
3863 }
3864
3865 void zmap::draw_secret(BITMAP *dest, int32_t pos)
3866 {
3867 word cmbdat = screens[TEMPLATE].data[pos];
3868 byte cmbcset = screens[TEMPLATE].cset[pos];
3869 int32_t cmbflag = screens[TEMPLATE].sflag[pos];
3870 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3871 }
3872
3873 void zmap::draw_secret2(BITMAP *dest, int32_t scombo)
3874 {
3875 word cmbdat = screens[cursor.screen].secretcombo[scombo];
3876 byte cmbcset = screens[cursor.screen].secretcset[scombo];
3877 byte cmbflag = screens[cursor.screen].secretflag[scombo];
3878 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3879 }
3880
3881 void zmap::scroll(int32_t dir, bool warp)
3882 {
3883 if(cursor.map<map_count)
3884 {
3885 switch(dir)
3886 {
3887 case up:
3888 if(warp && Map.CurrScr()->flags2&wfUP)
3889 {
3890 dowarp(1,Map.CurrScr()->sidewarpindex&3);
3891 }
3892 else if(cursor.screen>15)
3893 {
3894 setCurrScr(cursor.screen - 16);
3895 }
3896
3897 break;
3898
3899 case down:
3900 if(warp && Map.CurrScr()->flags2&wfDOWN)
3901 {
3902 dowarp(1,(Map.CurrScr()->sidewarpindex>>2)&3);
3903 }
3904 else if(cursor.screen<MAPSCRS-16)
3905 {
3906 setCurrScr(cursor.screen + 16);
3907 }
3908
3909 break;
3910
3911 case left:
3912 if(warp && Map.CurrScr()->flags2&wfLEFT)
3913 {
3914 dowarp(1,(Map.CurrScr()->sidewarpindex>>4)&3);
3915 }
3916 else if(cursor.screen&15)
3917 {
3918 setCurrScr(cursor.screen - 1);
3919 }
3920
3921 break;
3922
3923 case right:
3924 if(warp && Map.CurrScr()->flags2&wfRIGHT)
3925 {
3926 dowarp(1,(Map.CurrScr()->sidewarpindex>>6)&3);
3927 }
3928 else if((cursor.screen&15)<15 && cursor.screen<MAPSCRS-1)
3929 {
3930 setCurrScr(cursor.screen + 1);
3931 }
3932
3933 break;
3934 }
3935 }
3936 }
3937
3938 void fetch_door(int side, int door, int dcs, word data[176], byte cset[176])
3939 {
3940 switch(side)
3941 {
3942 case up:
3943 switch(door)
3944 {
3945 case dWALL:
3946 case dBOMB:
3947 case dWALK:
3948 data[7] = DoorComboSets[dcs].doorcombo_u[dt_wall][0];
3949 cset[7] = DoorComboSets[dcs].doorcset_u[dt_wall][0];
3950 data[8] = DoorComboSets[dcs].doorcombo_u[dt_wall][1];
3951 cset[8] = DoorComboSets[dcs].doorcset_u[dt_wall][1];
3952 data[23] = DoorComboSets[dcs].doorcombo_u[dt_wall][2];
3953 cset[23] = DoorComboSets[dcs].doorcset_u[dt_wall][2];
3954 data[24] = DoorComboSets[dcs].doorcombo_u[dt_wall][3];
3955 cset[24] = DoorComboSets[dcs].doorcset_u[dt_wall][3];
3956 break;
3957
3958 default:
3959 data[7] = DoorComboSets[dcs].doorcombo_u[dt_pass][0];
3960 cset[7] = DoorComboSets[dcs].doorcset_u[dt_pass][0];
3961 data[8] = DoorComboSets[dcs].doorcombo_u[dt_pass][1];
3962 cset[8] = DoorComboSets[dcs].doorcset_u[dt_pass][1];
3963 data[23] = DoorComboSets[dcs].doorcombo_u[dt_pass][2];
3964 cset[23] = DoorComboSets[dcs].doorcset_u[dt_pass][2];
3965 data[24] = DoorComboSets[dcs].doorcombo_u[dt_pass][3];
3966 cset[24] = DoorComboSets[dcs].doorcset_u[dt_pass][3];
3967 break;
3968 }
3969
3970 break;
3971
3972 case down:
3973 switch(door)
3974 {
3975 case dWALL:
3976 case dBOMB:
3977 case dWALK:
3978 data[151] = DoorComboSets[dcs].doorcombo_d[dt_wall][0];
3979 cset[151] = DoorComboSets[dcs].doorcset_d[dt_wall][0];
3980 data[152] = DoorComboSets[dcs].doorcombo_d[dt_wall][1];
3981 cset[152] = DoorComboSets[dcs].doorcset_d[dt_wall][1];
3982 data[167] = DoorComboSets[dcs].doorcombo_d[dt_wall][2];
3983 cset[167] = DoorComboSets[dcs].doorcset_d[dt_wall][2];
3984 data[168] = DoorComboSets[dcs].doorcombo_d[dt_wall][3];
3985 cset[168] = DoorComboSets[dcs].doorcset_d[dt_wall][3];
3986 break;
3987
3988 default:
3989 data[151] = DoorComboSets[dcs].doorcombo_d[dt_pass][0];
3990 cset[151] = DoorComboSets[dcs].doorcset_d[dt_pass][0];
3991 data[152] = DoorComboSets[dcs].doorcombo_d[dt_pass][1];
3992 cset[152] = DoorComboSets[dcs].doorcset_d[dt_pass][1];
3993 data[167] = DoorComboSets[dcs].doorcombo_d[dt_pass][2];
3994 cset[167] = DoorComboSets[dcs].doorcset_d[dt_pass][2];
3995 data[168] = DoorComboSets[dcs].doorcombo_d[dt_pass][3];
3996 cset[168] = DoorComboSets[dcs].doorcset_d[dt_pass][3];
3997 break;
3998 }
3999
4000 break;
4001
4002 case left:
4003 switch(door)
4004 {
4005 case dWALL:
4006 case dBOMB:
4007 case dWALK:
4008 data[64] = DoorComboSets[dcs].doorcombo_l[dt_wall][0];
4009 cset[64] = DoorComboSets[dcs].doorcset_l[dt_wall][0];
4010 data[65] = DoorComboSets[dcs].doorcombo_l[dt_wall][1];
4011 cset[65] = DoorComboSets[dcs].doorcset_l[dt_wall][1];
4012 data[80] = DoorComboSets[dcs].doorcombo_l[dt_wall][2];
4013 cset[80] = DoorComboSets[dcs].doorcset_l[dt_wall][2];
4014 data[81] = DoorComboSets[dcs].doorcombo_l[dt_wall][3];
4015 cset[81] = DoorComboSets[dcs].doorcset_l[dt_wall][3];
4016 data[96] = DoorComboSets[dcs].doorcombo_l[dt_wall][4];
4017 cset[96] = DoorComboSets[dcs].doorcset_l[dt_wall][4];
4018 data[97] = DoorComboSets[dcs].doorcombo_l[dt_wall][5];
4019 cset[97] = DoorComboSets[dcs].doorcset_l[dt_wall][5];
4020 break;
4021
4022 default:
4023 data[64] = DoorComboSets[dcs].doorcombo_l[dt_pass][0];
4024 cset[64] = DoorComboSets[dcs].doorcset_l[dt_pass][0];
4025 data[65] = DoorComboSets[dcs].doorcombo_l[dt_pass][1];
4026 cset[65] = DoorComboSets[dcs].doorcset_l[dt_pass][1];
4027 data[80] = DoorComboSets[dcs].doorcombo_l[dt_pass][2];
4028 cset[80] = DoorComboSets[dcs].doorcset_l[dt_pass][2];
4029 data[81] = DoorComboSets[dcs].doorcombo_l[dt_pass][3];
4030 cset[81] = DoorComboSets[dcs].doorcset_l[dt_pass][3];
4031 data[96] = DoorComboSets[dcs].doorcombo_l[dt_pass][4];
4032 cset[96] = DoorComboSets[dcs].doorcset_l[dt_pass][4];
4033 data[97] = DoorComboSets[dcs].doorcombo_l[dt_pass][5];
4034 cset[97] = DoorComboSets[dcs].doorcset_l[dt_pass][5];
4035 break;
4036 }
4037
4038 break;
4039
4040 case right:
4041 switch(door)
4042 {
4043 case dWALL:
4044 case dBOMB:
4045 case dWALK:
4046 data[78] = DoorComboSets[dcs].doorcombo_r[dt_wall][0];
4047 cset[78] = DoorComboSets[dcs].doorcset_r[dt_wall][0];
4048 data[79] = DoorComboSets[dcs].doorcombo_r[dt_wall][1];
4049 cset[79] = DoorComboSets[dcs].doorcset_r[dt_wall][1];
4050 data[94] = DoorComboSets[dcs].doorcombo_r[dt_wall][2];
4051 cset[94] = DoorComboSets[dcs].doorcset_r[dt_wall][2];
4052 data[95] = DoorComboSets[dcs].doorcombo_r[dt_wall][3];
4053 cset[95] = DoorComboSets[dcs].doorcset_r[dt_wall][3];
4054 data[110] = DoorComboSets[dcs].doorcombo_r[dt_wall][4];
4055 cset[110] = DoorComboSets[dcs].doorcset_r[dt_wall][4];
4056 data[111] = DoorComboSets[dcs].doorcombo_r[dt_wall][5];
4057 cset[111] = DoorComboSets[dcs].doorcset_r[dt_wall][5];
4058 break;
4059
4060 default:
4061 data[78] = DoorComboSets[dcs].doorcombo_r[dt_pass][0];
4062 cset[78] = DoorComboSets[dcs].doorcset_r[dt_pass][0];
4063 data[79] = DoorComboSets[dcs].doorcombo_r[dt_pass][1];
4064 cset[79] = DoorComboSets[dcs].doorcset_r[dt_pass][1];
4065 data[94] = DoorComboSets[dcs].doorcombo_r[dt_pass][2];
4066 cset[94] = DoorComboSets[dcs].doorcset_r[dt_pass][2];
4067 data[95] = DoorComboSets[dcs].doorcombo_r[dt_pass][3];
4068 cset[95] = DoorComboSets[dcs].doorcset_r[dt_pass][3];
4069 data[110] = DoorComboSets[dcs].doorcombo_r[dt_pass][4];
4070 cset[110] = DoorComboSets[dcs].doorcset_r[dt_pass][4];
4071 data[111] = DoorComboSets[dcs].doorcombo_r[dt_pass][5];
4072 cset[111] = DoorComboSets[dcs].doorcset_r[dt_pass][5];
4073 break;
4074 }
4075
4076 break;
4077 }
4078 }
4079 void zmap::DoPutDoorCommand(int side, int door, bool force)
4080 {
4081 if(!force && screens[cursor.screen].door[side] == door)
4082 return;
4083 bool already_list = InListCommand();
4084 if(!already_list)
4085 StartListCommand();
4086 DoSetDoorCommand(cursor.screen,side,door);
4087 if(door != dNONE)
4088 {
4089 word data[176] = {0};
4090 byte cset[176] = {0};
4091 fetch_door(side, door, screens[cursor.screen].door_combo_set, data, cset);
4092 for(int q = 0; q < 176; ++q)
4093 if(data[q])
4094 DoSetComboCommand(cursor.map,cursor.screen,q,data[q],cset[q]);
4095 }
4096 if(!already_list)
4097 FinishListCommand();
4098 }
4099 void zmap::putdoor(int32_t screen,int32_t side,int32_t door)
4100 {
4101 if(screens[screen].door[side] == door)
4102 return;
4103
4104 screens[screen].door[side] = door;
4105 if(door != dNONE)
4106 {
4107 word data[176] = {0};
4108 byte cset[176] = {0};
4109 fetch_door(side, door, screens[screen].door_combo_set, data, cset);
4110 for(int q = 0; q < 176; ++q)
4111 if(data[q])
4112 {
4113 screens[screen].data[q] = data[q];
4114 screens[screen].cset[q] = cset[q];
4115 }
4116 }
4117 }
4118
4119 void list_command::execute()
4120 {
4121 for (auto command : commands)
4122 {
4123 command->execute();
4124 }
4125 }
4126
4127 void list_command::undo()
4128 {
4129 for (int i = commands.size() - 1; i >= 0; i--)
4130 {
4131 commands[i]->undo();
4132 }
4133 }
4134
4135 int list_command::size()
4136 {
4137 int s = 0;
4138 for (auto command : commands)
4139 {
4140 s += command->size();
4141 }
4142 return s;
4143 }
4144
4145 void set_combo_command::execute()
4146 {
4147 mapscr* scr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4148 if (!scr_ptr) return;
4149
4150 if (combo != -1) scr_ptr->data[pos] = combo;
4151 scr_ptr->cset[pos] = cset;
4152 }
4153
4154 void set_combo_command::undo()
4155 {
4156 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4157 if(!mapscr_ptr) return;
4158 if (combo != -1) mapscr_ptr->data[pos] = prev_combo;
4159 mapscr_ptr->cset[pos] = prev_cset;
4160 }
4161
4162 set_ffc_command::data_t set_ffc_command::create_data(const ffcdata& ffc)
4163 {
4164 std::array<int, 8> initd_arr;
4165 std::copy(std::begin(ffc.initd), std::end(ffc.initd), initd_arr.begin());
4166
4167 return {
4168 .x = ffc.x,
4169 .y = ffc.y,
4170 .vx = ffc.vx,
4171 .vy = ffc.vy,
4172 .ax = ffc.ax,
4173 .ay = ffc.ay,
4174 .data = ffc.data,
4175 .cset = ffc.cset,
4176 .delay = ffc.delay,
4177 .link = ffc.link,
4178 .script = ffc.script,
4179 .tw = ffc.txsz,
4180 .th = ffc.tysz,
4181 .ew = ffc.hit_width,
4182 .eh = ffc.hit_height,
4183 .flags = ffc.flags,
4184 .initd = initd_arr,
4185 .layer = ffc.layer
4186 };
4187 }
4188
4189 void set_ffc_command::execute()
4190 {
4191 mapscr* mapscr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4192 if(!mapscr_ptr) return;
4193
4194 mapscr_ptr->valid |= mVALID;
4195 mapscr_ptr->ffcs[i].x = data.x;
4196 mapscr_ptr->ffcs[i].y = data.y;
4197 mapscr_ptr->ffcs[i].vx = data.vx;
4198 mapscr_ptr->ffcs[i].vy = data.vy;
4199 mapscr_ptr->ffcs[i].ax = data.ax;
4200 mapscr_ptr->ffcs[i].ay = data.ay;
4201 mapscr_ptr->ffcs[i].data = data.data;
4202 mapscr_ptr->ffcs[i].cset = data.cset;
4203 mapscr_ptr->ffcs[i].delay = data.delay;
4204 mapscr_ptr->ffcs[i].link = data.link;
4205 mapscr_ptr->ffcs[i].script = data.script;
4206 mapscr_ptr->ffcs[i].flags = data.flags;
4207 mapscr_ptr->ffEffectWidth(i, data.ew);
4208 mapscr_ptr->ffEffectHeight(i, data.eh);
4209 mapscr_ptr->ffTileWidth(i, data.tw);
4210 mapscr_ptr->ffTileHeight(i, data.th);
4211 std::copy(std::begin(data.initd), std::end(data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4212 mapscr_ptr->ffcs[i].layer = data.layer;
4213 mapscr_ptr->ffcCountMarkDirty();
4214 mapscr_ptr->ffcs[i].updateSolid();
4215 }
4216
4217 void set_ffc_command::undo()
4218 {
4219 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4220 if(!mapscr_ptr) return;
4221
4222 mapscr_ptr->ffcs[i].x = prev_data.x;
4223 mapscr_ptr->ffcs[i].y = prev_data.y;
4224 mapscr_ptr->ffcs[i].vx = prev_data.vx;
4225 mapscr_ptr->ffcs[i].vy = prev_data.vy;
4226 mapscr_ptr->ffcs[i].ax = prev_data.ax;
4227 mapscr_ptr->ffcs[i].ay = prev_data.ay;
4228 mapscr_ptr->ffcs[i].data = prev_data.data;
4229 mapscr_ptr->ffcs[i].cset = prev_data.cset;
4230 mapscr_ptr->ffcs[i].delay = prev_data.delay;
4231 mapscr_ptr->ffcs[i].link = prev_data.link;
4232 mapscr_ptr->ffcs[i].script = prev_data.script;
4233 mapscr_ptr->ffcs[i].flags = prev_data.flags;
4234 mapscr_ptr->ffEffectWidth(i, prev_data.ew);
4235 mapscr_ptr->ffEffectHeight(i, prev_data.eh);
4236 mapscr_ptr->ffTileWidth(i, prev_data.tw);
4237 mapscr_ptr->ffTileHeight(i, prev_data.th);
4238 std::copy(std::begin(prev_data.initd), std::end(prev_data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4239 mapscr_ptr->ffcs[i].layer = prev_data.layer;
4240 mapscr_ptr->ffcCountMarkDirty();
4241 mapscr_ptr->ffcs[i].updateSolid();
4242 }
4243
4244 void set_flag_command::execute()
4245 {
4246 mapscr* mapscr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4247 if(!mapscr_ptr) return;
4248
4249 mapscr_ptr->valid |= mVALID;
4250 mapscr_ptr->sflag[pos] = flag;
4251 }
4252
4253 void set_flag_command::undo()
4254 {
4255 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4256 if(!mapscr_ptr) return;
4257 mapscr_ptr->sflag[pos] = prev_flag;
4258 }
4259
4260 void set_door_command::execute()
4261 {
4262 auto* mapscr_ptr = Map.AbsoluteScrMakeValid(cursor.map, cursor.screen);
4263 if(!mapscr_ptr) return;
4264
4265 mapscr_ptr->valid |= mVALID;
4266 mapscr_ptr->door[side] = door;
4267 }
4268
4269 void set_door_command::undo()
4270 {
4271 Map.AbsoluteScr(cursor.map, cursor.screen)->door[side] = prev_door;
4272 }
4273
4274 void set_dcs_command::execute()
4275 {
4276 auto* mapscr_ptr = Map.AbsoluteScrMakeValid(cursor.map, cursor.screen);
4277 if(!mapscr_ptr) return;
4278
4279 mapscr_ptr->valid |= mVALID;
4280 mapscr_ptr->door_combo_set = dcs;
4281 }
4282
4283 void set_dcs_command::undo()
4284 {
4285 Map.AbsoluteScr(cursor.map, cursor.screen)->door_combo_set = prev_dcs;
4286 }
4287
4288 void paste_screen_command::execute()
4289 {
4290 perform(screen.get());
4291 }
4292
4293 void paste_screen_command::undo()
4294 {
4295 if (prev_screens.size() > 1)
4296 {
4297 ASSERT(type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen);
4298 ASSERT(prev_screens.size() == 128);
4299 for (int i = 0; i < 128; i++)
4300 {
4301 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, i), prev_screens[i].get());
4302 // TODO: why not just this?
4303 // If this changes, also change the line in PasteAllToAll and PasteAll to use simply copy assignment.
4304 // *Map.AbsoluteScr(map, i) = *prev_screens[i].get();
4305 }
4306 return;
4307 }
4308
4309 perform(prev_screens[0].get());
4310 }
4311
4312 int paste_screen_command::size()
4313 {
4314 return prev_screens.size() + 1;
4315 }
4316
4317 void paste_screen_command::perform(mapscr* to)
4318 {
4319 if (to)
4320 {
4321 switch (type) {
4322 case ScreenAll: Map.PasteAll(*to, screen_index); break;
4323 case ScreenAllToEveryScreen: Map.PasteAllToAll(*to); break;
4324 case ScreenData: Map.PasteScreenData(*to, screen_index); break;
4325 case ScreenDoors: Map.PasteDoors(*to, screen_index); break;
4326 case ScreenEnemies: Map.PasteEnemies(*to, screen_index); break;
4327 case ScreenFFCombos: Map.PasteFFCombos(*to, screen_index); break;
4328 case ScreenGuy: Map.PasteGuy(*to, screen_index); break;
4329 case ScreenLayers: Map.PasteLayers(*to, screen_index); break;
4330 case ScreenPalette: Map.PastePalette(*to, screen_index); break;
4331 case ScreenPartial: Map.Paste(*to, screen_index); break;
4332 case ScreenPartialToEveryScreen: Map.PasteToAll(*to); break;
4333 case ScreenRoom: Map.PasteRoom(*to, screen_index); break;
4334 case ScreenSecretCombos: Map.PasteSecretCombos(*to, screen_index); break;
4335 case ScreenUnderCombo: Map.PasteUnderCombo(*to, screen_index); break;
4336 case ScreenWarpLocations: Map.PasteWarpLocations(*to, screen_index); break;
4337 case ScreenWarps: Map.PasteWarps(*to, screen_index); break;
4338 }
4339 }
4340 else
4341 {
4342 Map.clearscr(screen_index);
4343 }
4344 refresh(rALL);
4345 }
4346
4347 void set_screen_command::execute()
4348 {
4349 if (screen)
4350 {
4351 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, screen_index), screen.get());
4352 }
4353 else
4354 {
4355 Map.clearscr(screen_index);
4356 }
4357 refresh(rALL);
4358 }
4359
4360 void set_screen_command::undo()
4361 {
4362 if (prev_screen)
4363 {
4364 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, screen_index), prev_screen.get());
4365 }
4366 else
4367 {
4368 Map.clearscr(screen_index);
4369 }
4370 refresh(rALL);
4371 }
4372
4373 int set_screen_command::size()
4374 {
4375 return (prev_screen ? 1 : 0) + (screen ? 1 : 0);
4376 }
4377
4378 static std::shared_ptr<list_command> current_list_command;
4379 void zmap::StartListCommand()
4380 {
4381 ASSERT(!current_list_command);
4382 current_list_command.reset(new list_command);
4383 }
4384
4385 void zmap::FinishListCommand()
4386 {
4387 if (current_list_command->commands.size() == 1)
4388 {
4389 input_undo_stack.push_back(current_list_command->commands[0]);
4390 }
4391 else if (current_list_command->commands.size() > 1)
4392 {
4393 input_undo_stack.push_back(current_list_command);
4394 }
4395 CapCommandHistory();
4396 current_list_command = nullptr;
4397 }
4398
4399 void zmap::RevokeListCommand()
4400 {
4401 current_list_command->undo();
4402 current_list_command = nullptr;
4403 }
4404
4405 bool zmap::InListCommand() const
4406 {
4407 return current_list_command ? true : false;
4408 }
4409
4410 void zmap::ExecuteCommand(std::shared_ptr<user_input_command> command, bool skip_execute)
4411 {
4412 input_redo_stack = {};
4413
4414 if (!skip_execute) command->execute();
4415 if (current_list_command)
4416 {
4417 current_list_command->commands.push_back(command);
4418 if (current_list_command->commands.size() == 1)
4419 {
4420 current_list_command->cursor = command->cursor;
4421 }
4422 }
4423 else
4424 {
4425 input_undo_stack.push_back(command);
4426 CapCommandHistory();
4427 }
4428 saved = false;
4429 }
4430
4431 void zmap::UndoCommand()
4432 {
4433 if (input_undo_stack.size() <= 0) return;
4434
4435 // If not currently looking at the associated screen, first change the view
4436 // and wait for the next call to actually undo this command.
4437 auto command = input_undo_stack.back();
4438 if (command->cursor.map != Map.getCurrMap() || command->cursor.screen != Map.getCurrScr())
4439 {
4440 setCursor(command.get()->cursor);
4441 return;
4442 }
4443
4444 command->undo();
4445 input_redo_stack.push(command);
4446 input_undo_stack.pop_back();
4447 saved = false;
4448 }
4449
4450 void zmap::RedoCommand()
4451 {
4452 if (input_redo_stack.size() <= 0) return;
4453
4454 // If not currently selected the associated screen, first change the cursor
4455 // and wait for the next call to actually execute this command.
4456 auto command = input_redo_stack.top();
4457 if (command->cursor.map != Map.getCurrMap() || command->cursor.screen != Map.getCurrScr())
4458 {
4459 setCursor(command.get()->cursor);
4460 return;
4461 }
4462
4463 command->execute();
4464 input_undo_stack.push_back(command);
4465 input_redo_stack.pop();
4466 saved = false;
4467 }
4468
4469 11 void zmap::ClearCommandHistory()
4470 {
4471 11 current_list_command = nullptr;
4472 11 input_undo_stack = {};
4473 11 input_redo_stack = {};
4474 11 }
4475
4476 // Extra amount is from mapscr's vectors.
4477 static int size_of_mapscr = sizeof(mapscr) + 4*176;
4478 // Allow the undo system to use roughly 100 MB of memory.
4479 // This doesn't count the memory used by commands that don't store a mapscr,
4480 // but that should be negligible.
4481 12 static int max_command_size = 100e6 / size_of_mapscr;
4482 void zmap::CapCommandHistory()
4483 {
4484 int size;
4485 do
4486 {
4487 size = 0;
4488 for (auto command : input_undo_stack)
4489 {
4490 size += command->size();
4491 }
4492 if (size > max_command_size) input_undo_stack.pop_front();
4493 } while (size > max_command_size);
4494 }
4495
4496 void zmap::DoSetComboCommand(ComboPosition pos, int combo, int cset)
4497 {
4498 if (!pos.is_valid(cursor))
4499 return;
4500
4501 int map = cursor.map;
4502 int screen = cursor.viewscr + pos.screen_offset();
4503 if (!AbsoluteScr(map, screen))
4504 return;
4505
4506 if (CurrentLayer)
4507 {
4508 mapscr* scr = AbsoluteScrMakeValid(map, screen);
4509 map = scr->layermap[CurrentLayer-1]-1;
4510 screen = scr->layerscreen[CurrentLayer-1];
4511 }
4512 DoSetComboCommand(map, screen, pos.truncate(), combo, cset);
4513 }
4514
4515 void zmap::DoSetComboCommand(int map, int scr, int pos, int combo, int cset)
4516 {
4517 mapscr* mapscr_ptr = AbsoluteScrMakeValid(map, scr);
4518 if (!mapscr_ptr) return;
4519
4520 std::shared_ptr<set_combo_command> command(new set_combo_command);
4521 command->cursor = cursor;
4522 command->map = map;
4523 command->scr = scr;
4524 command->pos = pos;
4525 command->combo = combo;
4526 command->cset = cset;
4527 command->prev_combo = mapscr_ptr->data[pos];
4528 command->prev_cset = mapscr_ptr->cset[pos];
4529 if ((command->combo != -1 && command->prev_combo == command->combo) && command->cset == command->prev_cset)
4530 {
4531 // nothing to do...
4532 return;
4533 }
4534
4535 ExecuteCommand(command);
4536 }
4537
4538 void zmap::DoSetFFCCommand(int map, int scr, int i, set_ffc_command::data_t data)
4539 {
4540 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4541 if(!mapscr_ptr) return;
4542
4543 mapscr_ptr->ensureFFC(i);
4544
4545 std::shared_ptr<set_ffc_command> command(new set_ffc_command);
4546
4547 std::array<int, 8> initd_arr;
4548 std::copy(std::begin(mapscr_ptr->ffcs[i].initd), std::end(mapscr_ptr->ffcs[i].initd), initd_arr.begin());
4549
4550 auto prev_data = set_ffc_command::create_data(mapscr_ptr->ffcs[i]);
4551
4552 command->cursor = cursor;
4553 command->map = map;
4554 command->scr = scr;
4555 command->i = i;
4556 command->data = data;
4557 command->prev_data = prev_data;
4558 if (data == prev_data)
4559 {
4560 // nothing to do...
4561 return;
4562 }
4563
4564 ExecuteCommand(command);
4565 }
4566
4567 void zmap::DoSetFlagCommand(ComboPosition pos, int flag)
4568 {
4569 if (!pos.is_valid(cursor))
4570 return;
4571
4572 int map = cursor.map;
4573 int screen = cursor.viewscr + pos.screen_offset();
4574 if (!AbsoluteScr(map, screen))
4575 return;
4576
4577 if (CurrentLayer)
4578 {
4579 mapscr* scr = AbsoluteScrMakeValid(map, screen);
4580 map = scr->layermap[CurrentLayer-1]-1;
4581 screen = scr->layerscreen[CurrentLayer-1];
4582 }
4583 DoSetFlagCommand(map, screen, pos.truncate(), flag);
4584 }
4585
4586 void zmap::DoSetFlagCommand(int map, int scr, int pos, int flag)
4587 {
4588 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4589 if(!mapscr_ptr) return;
4590
4591 std::shared_ptr<set_flag_command> command(new set_flag_command);
4592 command->cursor = cursor;
4593 command->map = map;
4594 command->scr = scr;
4595 command->pos = pos;
4596 command->flag = flag;
4597 command->prev_flag = mapscr_ptr->sflag[pos];
4598 if (command->flag == command->prev_flag)
4599 {
4600 // nothing to do...
4601 return;
4602 }
4603
4604 ExecuteCommand(command);
4605 }
4606
4607 void zmap::DoSetDoorCommand(int scr, int side, int door)
4608 {
4609 if(screens[scr].door[side] == door)
4610 return;
4611 std::shared_ptr<set_door_command> command(new set_door_command);
4612 command->cursor = cursor;
4613 command->side = side;
4614 command->door = door;
4615 command->prev_door = screens[scr].door[side];
4616
4617 ExecuteCommand(command);
4618 }
4619 void zmap::DoSetDCSCommand(int dcs)
4620 {
4621 if(screens[cursor.screen].door_combo_set == dcs)
4622 return;
4623 std::shared_ptr<set_dcs_command> command(new set_dcs_command);
4624 command->cursor = cursor;
4625 command->dcs = dcs;
4626 command->prev_dcs = screens[cursor.screen].door_combo_set;
4627
4628 ExecuteCommand(command);
4629 }
4630
4631 void zmap::DoPasteScreenCommand(PasteCommandType type, int screen)
4632 {
4633 if (screen == -1)
4634 screen = cursor.screen;
4635
4636 std::shared_ptr<paste_screen_command> command(new paste_screen_command);
4637 command->cursor = cursor;
4638 command->type = type;
4639 command->screen = std::shared_ptr<mapscr>(new mapscr(copymapscr));
4640 command->screen_index = screen;
4641
4642 if (type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen)
4643 {
4644 for (int i=0; i < 128; i++)
4645 {
4646 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[i])));
4647 }
4648 }
4649 else
4650 {
4651 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[screen])));
4652 }
4653
4654 ExecuteCommand(command);
4655 }
4656
4657 void zmap::DoClearScreenCommand(int screen)
4658 {
4659 std::shared_ptr<set_screen_command> command(new set_screen_command);
4660 command->cursor = cursor;
4661 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(screens[screen]));
4662 command->screen = std::shared_ptr<mapscr>(nullptr);
4663 command->screen_index = screen;
4664
4665 ExecuteCommand(command);
4666 }
4667
4668 void zmap::DoTemplateCommand(int floorcombo, int floorcset, int screen)
4669 {
4670 std::shared_ptr<set_screen_command> command(new set_screen_command);
4671 command->cursor = cursor;
4672 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(*Map.Scr(screen)));
4673 Template(floorcombo, floorcset, screen);
4674 command->screen = std::shared_ptr<mapscr>(new mapscr(*Map.Scr(screen)));
4675
4676 ExecuteCommand(command, true);
4677 }
4678
4679 void zmap::Copy(int scr)
4680 {
4681 if(screens[scr].valid&mVALID)
4682 {
4683 copy_mapscr(&copymapscr, &screens[scr]);
4684 //copymapscr=screens[scr];
4685 can_paste=true;
4686 copymap=cursor.map;
4687 copyscr=scr;
4688 copyscrdata = zinit.screen_data[cursor.map*MAPSCRS+scr];
4689 copyffc = -1;
4690 }
4691 }
4692
4693 void zmap::CopyFFC(int32_t screen, int32_t n)
4694 {
4695 if(screens[screen].valid&mVALID)
4696 {
4697 copy_mapscr(&copymapscr, &screens[screen]);
4698 // Can't paste the screen itself
4699 can_paste = false;
4700 copymap=cursor.map;
4701 copyscr=screen;
4702 copyffc = n;
4703 }
4704 }
4705
4706 void zmap::Paste(const mapscr& copymapscr, int screen)
4707 {
4708 if(can_paste)
4709 {
4710 if(!(screens[screen].valid&mVALID))
4711 {
4712 screens[screen].valid |= mVALID;
4713 screens[screen].color = copymapscr.color;
4714 }
4715
4716 screens[screen].door_combo_set = copymapscr.door_combo_set;
4717
4718 for(int32_t i=0; i<4; i++)
4719 {
4720 screens[screen].door[i]=copymapscr.door[i];
4721 }
4722
4723 for(int32_t i=0; i<176; i++)
4724 {
4725 screens[screen].data[i] = copymapscr.data[i];
4726 screens[screen].cset[i] = copymapscr.cset[i];
4727 screens[screen].sflag[i] = copymapscr.sflag[i];
4728 }
4729
4730 refresh_color();
4731
4732 saved=false;
4733 }
4734 }
4735
4736 void zmap::PasteUnderCombo(const mapscr& copymapscr, int screen)
4737 {
4738 if(can_paste)
4739 {
4740 screens[screen].undercombo = copymapscr.undercombo;
4741 screens[screen].undercset = copymapscr.undercset;
4742 saved=false;
4743 }
4744 }
4745
4746 void zmap::PasteSecretCombos(const mapscr& copymapscr, int screen)
4747 {
4748 if(can_paste)
4749 {
4750 for(int32_t i=0; i<128; i++)
4751 {
4752 screens[screen].secretcombo[i] = copymapscr.secretcombo[i];
4753 screens[screen].secretcset[i] = copymapscr.secretcset[i];
4754 screens[screen].secretflag[i] = copymapscr.secretflag[i];
4755 }
4756
4757 saved=false;
4758 }
4759 }
4760
4761 // TODO const mapscr& copymapscr
4762 void zmap::PasteFFCombos(mapscr& copymapscr, int screen)
4763 {
4764 if(can_paste)
4765 {
4766 screens[screen].ffcs = copymapscr.ffcs;
4767 screens[screen].ffcCountMarkDirty();
4768 saved=false;
4769 }
4770 }
4771
4772 void zmap::PasteWarps(const mapscr& copymapscr, int screen)
4773 {
4774 if(can_paste)
4775 {
4776 screens[screen].sidewarpindex = copymapscr.sidewarpindex;
4777
4778 for(int32_t i=0; i<4; i++)
4779 {
4780 screens[screen].tilewarptype[i] = copymapscr.tilewarptype[i];
4781 screens[screen].tilewarpdmap[i] = copymapscr.tilewarpdmap[i];
4782 screens[screen].tilewarpscr[i] = copymapscr.tilewarpscr[i];
4783 screens[screen].sidewarptype[i] = copymapscr.sidewarptype[i];
4784 screens[screen].sidewarpdmap[i] = copymapscr.sidewarpdmap[i];
4785 screens[screen].sidewarpscr[i] = copymapscr.sidewarpscr[i];
4786 screens[screen].flags2 &= ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4787 screens[screen].flags2 |= copymapscr.flags2 & (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4788 screens[screen].sidewarpoverlayflags = copymapscr.sidewarpoverlayflags;
4789 screens[screen].tilewarpoverlayflags = copymapscr.tilewarpoverlayflags;
4790 }
4791
4792 saved=false;
4793 }
4794 }
4795
4796 void zmap::PasteScreenData(const mapscr& copymapscr, int screen)
4797 {
4798 if(can_paste)
4799 {
4800 screens[screen].csensitive = copymapscr.csensitive;
4801 screens[screen].oceansfx = copymapscr.oceansfx;
4802 screens[screen].bosssfx = copymapscr.bosssfx;
4803 screens[screen].secretsfx = copymapscr.secretsfx;
4804 screens[screen].holdupsfx = copymapscr.holdupsfx;
4805 screens[screen].flags = copymapscr.flags;
4806 screens[screen].flags2 &= (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4807 screens[screen].flags2 |= copymapscr.flags2 & ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4808 screens[screen].flags3 = copymapscr.flags3;
4809 screens[screen].flags4 = copymapscr.flags4;
4810 screens[screen].flags5 = copymapscr.flags5;
4811 screens[screen].flags6 = copymapscr.flags6;
4812 screens[screen].flags7 = copymapscr.flags7;
4813 screens[screen].flags8 = copymapscr.flags8;
4814 screens[screen].flags9 = copymapscr.flags9;
4815 screens[screen].flags10 = copymapscr.flags10;
4816 screens[screen].flags11 = copymapscr.flags11;
4817 screens[screen].item = copymapscr.item;
4818 screens[screen].hasitem = copymapscr.hasitem;
4819 screens[screen].itemx = copymapscr.itemx;
4820 screens[screen].itemy = copymapscr.itemy;
4821 screens[screen].nextmap = copymapscr.nextmap;
4822 screens[screen].nextscr = copymapscr.nextscr;
4823 screens[screen].nocarry = copymapscr.nocarry;
4824 screens[screen].noreset = copymapscr.noreset;
4825 screens[screen].exstate_reset = copymapscr.exstate_reset;
4826 screens[screen].exstate_carry = copymapscr.exstate_carry;
4827 screens[screen].path[0] = copymapscr.path[0];
4828 screens[screen].path[1] = copymapscr.path[1];
4829 screens[screen].path[2] = copymapscr.path[2];
4830 screens[screen].path[3] = copymapscr.path[3];
4831 screens[screen].pattern = copymapscr.pattern;
4832 screens[screen].exitdir = copymapscr.exitdir;
4833 screens[screen].screen_midi = copymapscr.screen_midi;
4834 screens[screen].stairx = copymapscr.stairx;
4835 screens[screen].stairy = copymapscr.stairy;
4836 screens[screen].timedwarptics = copymapscr.timedwarptics;
4837 saved=false;
4838 }
4839 }
4840
4841 void zmap::PasteWarpLocations(const mapscr& copymapscr, int screen)
4842 {
4843 if(can_paste)
4844 {
4845 screens[screen].warpreturnc = copymapscr.warpreturnc;
4846 screens[screen].warparrivalx = copymapscr.warparrivalx;
4847 screens[screen].warparrivaly = copymapscr.warparrivaly;
4848
4849 for(int32_t i=0; i<4; i++)
4850 {
4851 screens[screen].warpreturnx[i] = copymapscr.warpreturnx[i];
4852 screens[screen].warpreturny[i] = copymapscr.warpreturny[i];
4853 }
4854
4855 saved=false;
4856 }
4857 }
4858
4859 void zmap::PasteDoors(const mapscr& copymapscr, int screen)
4860 {
4861 if(can_paste)
4862 {
4863 for(int32_t i=0; i<4; i++)
4864 screens[screen].door[i] = copymapscr.door[i];
4865
4866 screens[screen].door_combo_set = copymapscr.door_combo_set;
4867 saved=false;
4868 }
4869 }
4870
4871 void zmap::PasteLayers(const mapscr& copymapscr, int screen)
4872 {
4873 if(can_paste)
4874 {
4875 for(int32_t i=0; i<6; i++)
4876 {
4877 screens[screen].layermap[i] = copymapscr.layermap[i];
4878 screens[screen].layerscreen[i] = copymapscr.layerscreen[i];
4879 screens[screen].layeropacity[i] = copymapscr.layeropacity[i];
4880 }
4881
4882 saved=false;
4883 }
4884 }
4885
4886 void zmap::PasteRoom(const mapscr& copymapscr, int screen)
4887 {
4888 if(can_paste)
4889 {
4890 screens[screen].room = copymapscr.room;
4891 screens[screen].catchall = copymapscr.catchall;
4892 saved=false;
4893 }
4894 }
4895
4896 void zmap::PasteGuy(const mapscr& copymapscr, int screen)
4897 {
4898 if(can_paste)
4899 {
4900 screens[screen].guy = copymapscr.guy;
4901 screens[screen].guytile = copymapscr.guytile;
4902 screens[screen].guycs = copymapscr.guycs;
4903 SETFLAG(screens[screen].roomflags,RFL_ALWAYS_GUY,copymapscr.roomflags&RFL_ALWAYS_GUY);
4904 SETFLAG(screens[screen].roomflags,RFL_GUYFIRES,copymapscr.roomflags&RFL_GUYFIRES);
4905 screens[screen].str = copymapscr.str;
4906 saved=false;
4907 }
4908 }
4909
4910 void zmap::PastePalette(const mapscr& copymapscr, int screen)
4911 {
4912 if(can_paste)
4913 {
4914 screens[screen].color = copymapscr.color;
4915 screens[screen].valid|=mVALID;
4916 refresh_color();
4917
4918 saved=false;
4919 }
4920 }
4921
4922 void zmap::PasteAll(const mapscr& copymapscr, int screen)
4923 {
4924 if(can_paste)
4925 {
4926 copy_mapscr(&screens[screen], &copymapscr);
4927 zinit.screen_data[cursor.map*MAPSCRS+cursor.screen] = copyscrdata;
4928 screens[screen].valid|=mVALID;
4929
4930 refresh_color();
4931
4932 saved=false;
4933 }
4934 }
4935
4936
4937 void zmap::PasteToAll(const mapscr& copymapscr)
4938 {
4939 if(can_paste)
4940 {
4941 for(int32_t x=0; x<128; x++)
4942 {
4943 if(!(screens[x].valid&mVALID))
4944 {
4945 screens[x].valid |= mVALID;
4946 screens[x].color = copymapscr.color;
4947 }
4948
4949 for(int32_t i=0; i<176; i++)
4950 {
4951 screens[x].data[i] = copymapscr.data[i];
4952 screens[x].cset[i] = copymapscr.cset[i];
4953 screens[x].sflag[i] = copymapscr.sflag[i];
4954 }
4955 }
4956
4957 refresh_color();
4958
4959 saved=false;
4960 }
4961 }
4962
4963 void zmap::PasteAllToAll(const mapscr& copymapscr)
4964 {
4965 if(can_paste)
4966 {
4967 for(int32_t x=0; x<128; x++)
4968 {
4969 copy_mapscr(&screens[x], &copymapscr);
4970 zinit.screen_data[cursor.map*MAPSCRS+x] = copyscrdata;
4971 //screens[x]=copymapscr;
4972 }
4973
4974 refresh_color();
4975
4976 saved=false;
4977 }
4978 }
4979
4980 void zmap::PasteEnemies(const mapscr& copymapscr, int screen)
4981 {
4982 if(can_paste)
4983 {
4984 for(int32_t i=0; i<10; i++)
4985 screens[screen].enemy[i]=copymapscr.enemy[i];
4986 }
4987 }
4988
4989 bool zmap::CanGoBack() const
4990 {
4991 return !cursor_undo_stack.empty();
4992 }
4993
4994 bool zmap::CanGoForward() const
4995 {
4996 return !cursor_redo_stack.empty();
4997 }
4998
4999 void zmap::GoBack()
5000 {
5001 if (!CanGoBack())
5002 return;
5003
5004 cursor_redo_stack.push(cursor);
5005
5006 ConfigureCursorHistory(false);
5007 setCursor(cursor_undo_stack.back());
5008 ConfigureCursorHistory(true);
5009
5010 cursor_undo_stack.pop_back();
5011 }
5012
5013 void zmap::GoForward()
5014 {
5015 if (!CanGoForward())
5016 return;
5017
5018 cursor_undo_stack.push_back(cursor);
5019
5020 ConfigureCursorHistory(false);
5021 setCursor(cursor_redo_stack.top());
5022 ConfigureCursorHistory(true);
5023
5024 cursor_redo_stack.pop();
5025 }
5026
5027 void zmap::CapCursorHistory()
5028 {
5029 int max_history_size = 1000;
5030 while (cursor_undo_stack.size() > max_history_size)
5031 cursor_undo_stack.pop_front();
5032 }
5033
5034 void zmap::ConfigureCursorHistory(bool enable)
5035 {
5036 cursor_history_enabled = enable;
5037 }
5038
5039 void zmap::setCopyFFC(int32_t n)
5040 {
5041 copyffc = n;
5042 }
5043
5044 void zmap::update_combo_cycling()
5045 {
5046 if(!prv_mode||!prv_cmbcycle)
5047 {
5048 return;
5049 }
5050
5051 int32_t x;
5052 int32_t newdata[176];
5053 int32_t newcset[176];
5054 bool restartanim[MAXCOMBOS] = {0};
5055
5056 for(int32_t i=0; i<176; i++)
5057 {
5058 newdata[i]=-1;
5059 newcset[i]=-1;
5060
5061 x=prvscr.data[i];
5062
5063 //time to restart
5064 if((combobuf[x].aclk>=combobuf[x].speed) &&
5065 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5066 combobuf[x].can_cycle())
5067 {
5068 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5069 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5070
5071 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5072 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5073 int32_t c = newdata[i];
5074
5075 if(combobuf[c].animflags & AF_CYCLE)
5076 {
5077 restartanim[c]=true;
5078 }
5079 }
5080 }
5081
5082 for(int32_t i=0; i<176; i++)
5083 {
5084 x=prvscr.data[i];
5085
5086 //time to restart
5087 if((combobuf[x].aclk>=combobuf[x].speed) &&
5088 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5089 combobuf[x].can_cycle())
5090 {
5091 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5092 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5093
5094 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5095 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5096 int32_t c = newdata[i];
5097
5098 if(combobuf[c].animflags & AF_CYCLE)
5099 {
5100 restartanim[c]=true;
5101 }
5102 }
5103 }
5104
5105 for(int32_t i=0; i<176; i++)
5106 {
5107 if(newdata[i]==-1)
5108 continue;
5109
5110 prvscr.data[i]=newdata[i];
5111 prvscr.cset[i]=newcset[i];
5112 }
5113
5114 word maxffc = prvscr.numFFC();
5115 for(word i=0; i<maxffc; i++)
5116 {
5117 ffcdata& ffc = prvscr.ffcs[i];
5118 newcombo const& cmb = combobuf[ffc.data];
5119
5120 //time to restart
5121 if((cmb.aclk>=cmb.speed) &&
5122 (cmb.tile-cmb.frames>=cmb.o_tile-1) &&
5123 cmb.can_cycle())
5124 {
5125 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
5126 ffc.data = cycle_under ? prvscr.undercombo : cmb.nextcombo;
5127
5128 if(!(cmb.animflags & AF_CYCLENOCSET))
5129 newcset[i] = cycle_under ? prvscr.undercset : cmb.nextcset;
5130
5131 if(combobuf[ffc.data].animflags & AF_CYCLE)
5132 {
5133 restartanim[ffc.data]=true;
5134 }
5135 prvscr.ffcs[i].data = ffc.data;
5136 prvscr.ffcs[i].cset=ffc.cset;
5137 }
5138 }
5139
5140
5141 if(get_qr(qr_CMBCYCLELAYERS))
5142 {
5143 for(int32_t j=0; j<6; j++)
5144 {
5145 if(!prvlayers[j].valid)
5146 continue;
5147
5148 for(int32_t i=0; i<176; i++)
5149 {
5150 newdata[i]=-1;
5151 newcset[i]=-1;
5152
5153 x=(prvlayers[j]).data[i];
5154
5155 //time to restart
5156 if((combobuf[x].aclk>=combobuf[x].speed) &&
5157 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5158 combobuf[x].can_cycle())
5159 {
5160 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5161 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5162
5163 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5164 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5165 int32_t c = newdata[i];
5166
5167 if(combobuf[c].animflags & AF_CYCLE)
5168 {
5169 restartanim[c]=true;
5170 }
5171 }
5172 }
5173
5174 for(int32_t i=0; i<176; i++)
5175 {
5176 x=(prvlayers[j]).data[i];
5177
5178 //time to restart
5179 if((combobuf[x].aclk>=combobuf[x].speed) &&
5180 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5181 combobuf[x].can_cycle())
5182 {
5183 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5184 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5185
5186 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5187 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5188 int32_t c = newdata[i];
5189
5190 if(combobuf[c].animflags & AF_CYCLE)
5191 {
5192 restartanim[c]=true;
5193 }
5194 }
5195 }
5196
5197 for(int32_t i=0; i<176; i++)
5198 {
5199 if(newdata[i]==-1)
5200 continue;
5201
5202 prvlayers[j].data[i]=newdata[i];
5203 prvlayers[j].cset[i]=newcset[i];
5204 }
5205 }
5206 }
5207
5208 for(int32_t i=0; i<MAXCOMBOS; i++)
5209 {
5210 if(restartanim[i])
5211 {
5212 combobuf[i].tile = combobuf[i].o_tile;
5213 combobuf[i].cur_frame=0;
5214 combobuf[i].aclk = 0;
5215 }
5216 }
5217 }
5218
5219 void zmap::update_freeform_combos()
5220 {
5221 if(!prv_mode||!prv_cmbcycle)
5222 {
5223 return;
5224 }
5225
5226 // TODO: this changer code is a duplicated here and for zplayer. Should fix that.
5227 word maxffc = prvscr.numFFC();
5228 for(int32_t i=0; i<maxffc; i++)
5229 {
5230 if(!(prvscr.ffcs[i].flags&ffc_changer) && prvscr.ffcs[i].data!=0 && !(prvscr.ffcs[i].flags&ffc_stationary))
5231 {
5232 for(int32_t j=0; j<maxffc; j++)
5233 {
5234 if(i!=j)
5235 {
5236 if(prvscr.ffcs[j].flags&ffc_changer && prvscr.ffcs[j].data != 0)
5237 {
5238 if((((prvscr.ffcs[j].x.getInt())!=prvscr.ffcs[i].changer_x)||((prvscr.ffcs[j].y.getInt())!=prvscr.ffcs[i].changer_y))&&(prvscr.ffcs[i].link==0))
5239 {
5240 if((isonline(prvscr.ffcs[i].x.getZLong(),prvscr.ffcs[i].y.getZLong(),prvscr.ffcs[i].prev_changer_x,prvscr.ffcs[i].prev_changer_y,prvscr.ffcs[j].x.getZLong(),prvscr.ffcs[j].y.getZLong())||
5241 ((prvscr.ffcs[i].x.getZLong()==prvscr.ffcs[j].x.getZLong())&&(prvscr.ffcs[i].y.getZLong()==prvscr.ffcs[j].y.getZLong())))&&(prvscr.ffcs[i].prev_changer_x>-10000000&&prvscr.ffcs[i].prev_changer_y>-10000000))
5242 {
5243 //prvscr.ffcs[i].data=prvscr.ffcs[j].data;
5244 //prvscr.ffcs[i].cset=prvscr.ffcs[j].cset;
5245 if(prvscr.ffcs[j].flags&ffc_changethis)
5246 {
5247 prvscr.ffcs[i].data = prvscr.ffcs[j].data;
5248 prvscr.ffcs[i].cset = prvscr.ffcs[j].cset;
5249 }
5250
5251 if(prvscr.ffcs[j].flags&ffc_changenext)
5252 prvscr.ffcs[i].data += 1;
5253
5254 if(prvscr.ffcs[j].flags&ffc_changeprev)
5255 prvscr.ffcs[i].data -= 1;
5256
5257 prvscr.ffcs[i].delay=prvscr.ffcs[j].delay;
5258 prvscr.ffcs[i].x=prvscr.ffcs[j].x;
5259 prvscr.ffcs[i].y=prvscr.ffcs[j].y;
5260
5261 prvscr.ffcs[i].vx=prvscr.ffcs[j].vx;
5262 prvscr.ffcs[i].vy=prvscr.ffcs[j].vy;
5263 prvscr.ffcs[i].ax=prvscr.ffcs[j].ax;
5264 prvscr.ffcs[i].ay=prvscr.ffcs[j].ay;
5265
5266 prvscr.ffcs[i].link=prvscr.ffcs[j].link;
5267 prvscr.ffcs[i].hit_width=prvscr.ffcs[j].hit_width;
5268 prvscr.ffcs[i].hit_height=prvscr.ffcs[j].hit_height;
5269 prvscr.ffcs[i].txsz=prvscr.ffcs[j].txsz;
5270 prvscr.ffcs[i].tysz=prvscr.ffcs[j].tysz;
5271
5272 if(prvscr.ffcs[i].flags&ffc_carryover)
5273 prvscr.ffcs[i].flags=prvscr.ffcs[j].flags&ffc_carryover;
5274 else prvscr.ffcs[i].flags=prvscr.ffcs[j].flags;
5275
5276 prvscr.ffcs[i].flags&=~ffc_changer;
5277 prvscr.ffcs[i].changer_x=(prvscr.ffcs[j].x.getInt());
5278 prvscr.ffcs[i].changer_y=(prvscr.ffcs[j].y.getInt());
5279
5280 if(combobuf[prvscr.ffcs[j].data].flag>15 && combobuf[prvscr.ffcs[j].data].flag<32)
5281 {
5282 prvscr.ffcs[j].data = prvscr.secretcombo[combobuf[prvscr.ffcs[j].data].flag - 16 + 4];
5283 }
5284
5285 if((prvscr.ffcs[j].flags&ffc_swapnext)||(prvscr.ffcs[j].flags&ffc_swapprev))
5286 {
5287 int32_t k=0;
5288
5289 if(prvscr.ffcs[j].flags&ffc_swapnext)
5290 k=j<(MAXFFCS-1)?j+1:0;
5291
5292 if(prvscr.ffcs[j].flags&ffc_swapprev)
5293 k=j>0?j-1:(MAXFFCS-1);
5294
5295 zc_swap(prvscr.ffcs[j].vx,prvscr.ffcs[k].vx);
5296 zc_swap(prvscr.ffcs[j].vy,prvscr.ffcs[k].vy);
5297 zc_swap(prvscr.ffcs[j].ax,prvscr.ffcs[k].ax);
5298 zc_swap(prvscr.ffcs[j].ay,prvscr.ffcs[k].ay);
5299 zc_swap(prvscr.ffcs[j].link,prvscr.ffcs[k].link);
5300 zc_swap(prvscr.ffcs[j].hit_width,prvscr.ffcs[k].hit_width);
5301 zc_swap(prvscr.ffcs[j].hit_height,prvscr.ffcs[k].hit_height);
5302 zc_swap(prvscr.ffcs[j].txsz,prvscr.ffcs[k].txsz);
5303 zc_swap(prvscr.ffcs[j].tysz,prvscr.ffcs[k].tysz);
5304 zc_swap(prvscr.ffcs[j].flags,prvscr.ffcs[k].flags);
5305 }
5306 }
5307 }
5308 }
5309 }
5310 }
5311
5312 if(prvscr.ffcs[i].link ? !prvscr.ffcs[prvscr.ffcs[i].link].delay : !prvscr.ffcs[i].delay)
5313 {
5314 if(prvscr.ffcs[i].link&&(prvscr.ffcs[i].link-1)!=i)
5315 {
5316 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5317 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5318 prvscr.ffcs[i].x+=prvscr.ffcs[prvscr.ffcs[i].link-1].vx;
5319 prvscr.ffcs[i].y+=prvscr.ffcs[prvscr.ffcs[i].link-1].vy;
5320 }
5321 else
5322 {
5323 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5324 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5325 prvscr.ffcs[i].x+=prvscr.ffcs[i].vx;
5326 prvscr.ffcs[i].y+=prvscr.ffcs[i].vy;
5327 prvscr.ffcs[i].vx+=prvscr.ffcs[i].ax;
5328 prvscr.ffcs[i].vy+=prvscr.ffcs[i].ay;
5329
5330 if(get_qr(qr_OLD_FFC_SPEED_CAP))
5331 {
5332 if(prvscr.ffcs[i].vx>128) prvscr.ffcs[i].vx=128;
5333
5334 if(prvscr.ffcs[i].vx<-128) prvscr.ffcs[i].vx=-128;
5335
5336 if(prvscr.ffcs[i].vy>128) prvscr.ffcs[i].vy=128;
5337
5338 if(prvscr.ffcs[i].vy<-128) prvscr.ffcs[i].vy=-128;
5339 }
5340 }
5341 }
5342 else
5343 {
5344 if(!prvscr.ffcs[i].link || (prvscr.ffcs[i].link-1)==i)
5345 prvscr.ffcs[i].delay--;
5346 }
5347
5348 if(prvscr.ffcs[i].x<-32)
5349 {
5350 if(prvscr.flags6&fWRAPAROUNDFF)
5351 {
5352 prvscr.ffcs[i].x = (288+(prvscr.ffcs[i].x+32));
5353 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5354 }
5355 else
5356 {
5357 prvscr.ffcs[i].data = 0;
5358 prvscr.ffcs[i].flags&=~ffc_carryover;
5359 }
5360 }
5361
5362 if(prvscr.ffcs[i].y<-32)
5363 {
5364 if(prvscr.flags6&fWRAPAROUNDFF)
5365 {
5366 prvscr.ffcs[i].y = 208+(prvscr.ffcs[i].y+32);
5367 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5368 }
5369 else
5370 {
5371 prvscr.ffcs[i].data = 0;
5372 prvscr.ffcs[i].flags&=~ffc_carryover;
5373 }
5374 }
5375
5376 if(prvscr.ffcs[i].x>=288)
5377 {
5378 if(prvscr.flags6&fWRAPAROUNDFF)
5379 {
5380 prvscr.ffcs[i].x = prvscr.ffcs[i].x-288-32;
5381 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5382 }
5383 else
5384 {
5385 prvscr.ffcs[i].data = 0;
5386 prvscr.ffcs[i].flags&=~ffc_carryover;
5387 }
5388 }
5389
5390 if(prvscr.ffcs[i].y>=208)
5391 {
5392 if(prvscr.flags6&fWRAPAROUNDFF)
5393 {
5394 prvscr.ffcs[i].y = prvscr.ffcs[i].y-208-32;
5395 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].x.getZLong();
5396 }
5397 else
5398 {
5399 prvscr.ffcs[i].data = 0;
5400 prvscr.ffcs[i].flags&=~ffc_carryover;
5401 }
5402 }
5403
5404 }
5405 }
5406 }
5407
5408 void zmap::goto_dmapscr(int dmap, int scr)
5409 {
5410 goto_mapscr(DMaps[dmap].map, scr);
5411 }
5412 void zmap::goto_mapscr(int map, int scr)
5413 {
5414 auto new_cursor = cursor;
5415 new_cursor.map = map;
5416 new_cursor.setScreen(scr);
5417 setCursor(std::move(new_cursor));
5418 }
5419
5420 void zmap::dowarp(int32_t type, int32_t index)
5421 {
5422 set_warpback();
5423 if(type==0)
5424 {
5425
5426 int32_t dmap=screens[cursor.screen].tilewarpdmap[index];
5427 int32_t scr=screens[cursor.screen].tilewarpscr[index];
5428
5429 switch(screens[cursor.screen].tilewarptype[index])
5430 {
5431 case wtCAVE:
5432 case wtNOWARP:
5433 break;
5434
5435 default:
5436 goto_dmapscr(dmap, scr);
5437 break;
5438 }
5439 }
5440 else if(type==1)
5441 {
5442 int32_t dmap=screens[cursor.screen].sidewarpdmap[index];
5443 int32_t scr=screens[cursor.screen].sidewarpscr[index];
5444
5445 switch(screens[cursor.screen].sidewarptype[index])
5446 {
5447 case wtCAVE:
5448 case wtNOWARP:
5449 break;
5450
5451 default:
5452 goto_dmapscr(dmap, scr);
5453 break;
5454 }
5455 }
5456 }
5457
5458 extern int32_t prv_twon;
5459
5460 void zmap::prv_dowarp(int32_t type, int32_t index)
5461 {
5462 if(type==0)
5463 {
5464
5465 int32_t dmap=prvscr.tilewarpdmap[index];
5466 int32_t scr=prvscr.tilewarpscr[index];
5467
5468 switch(prvscr.tilewarptype[index])
5469 {
5470 case wtCAVE:
5471 case wtNOWARP:
5472 break;
5473
5474 default:
5475 //setCurrMap(DMaps[dmap].map);
5476 //setCurrScr(scr+DMaps[dmap].xoff);
5477 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5478 refresh_color();
5479 //prv_cmbcycle=0;
5480 break;
5481 }
5482 }
5483 else if(type==1)
5484 {
5485 int32_t dmap=prvscr.sidewarpdmap[index];
5486 int32_t scr=prvscr.sidewarpscr[index];
5487
5488 switch(prvscr.sidewarptype[index])
5489 {
5490 case wtCAVE:
5491 case wtNOWARP:
5492 break;
5493
5494 default:
5495 //setCurrMap(DMaps[dmap].map);
5496 //setCurrScr(scr+DMaps[dmap].xoff);
5497 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5498 refresh_color();
5499 //prv_cmbcycle=0;
5500 break;
5501 }
5502 }
5503
5504 if(prv_twon)
5505 {
5506 prv_time=get_prvscr()->timedwarptics;
5507 }
5508 }
5509
5510 void zmap::dowarp2(int32_t ring,int32_t index)
5511 {
5512 set_warpback();
5513 goto_dmapscr(QMisc.warp[ring].dmap[index], QMisc.warp[ring].scr[index]);
5514 }
5515
5516 void zmap::set_warpback()
5517 {
5518 warpbackmap = cursor.map;
5519 warpbackscreen = cursor.screen;
5520 }
5521 bool zmap::has_warpback()
5522 {
5523 return warpbackmap && warpbackscreen
5524 && !(warpbackmap == cursor.map && warpbackscreen == cursor.screen);
5525 }
5526 void zmap::warpback()
5527 {
5528 if(!has_warpback())
5529 return;
5530
5531 int m = cursor.map, s = cursor.screen;
5532 goto_mapscr(*warpbackmap, *warpbackscreen);
5533 warpbackmap = m;
5534 warpbackscreen = s;
5535 }
5536
5537 bool save_msgstrs(const char *path)
5538 {
5539 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5540
5541 if(!f)
5542 {
5543 return false;
5544 }
5545
5546 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)==0)
5547 {
5548 pack_fclose(f);
5549 return true;
5550 }
5551
5552 pack_fclose(f);
5553 return false;
5554 }
5555
5556 1 bool save_strings_tsv(const char *path)
5557 {
5558 1 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5559
5560
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(!f)
5561 {
5562 return false;
5563 }
5564
5565
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(writestrings_tsv(f)==0)
5566 {
5567 1 pack_fclose(f);
5568 1 return true;
5569 }
5570
5571 pack_fclose(f);
5572 return false;
5573 1 }
5574
5575 bool save_msgstrs_text(const char *path)
5576 {
5577 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5578
5579 if(!f)
5580 {
5581 return false;
5582 }
5583
5584 if(writestrings_text(f)==0)
5585 {
5586 pack_fclose(f);
5587 return true;
5588 }
5589
5590 pack_fclose(f);
5591 return false;
5592 }
5593
5594 bool load_msgstrs(const char *path, int32_t startstring)
5595 {
5596 //these are here to bypass compiler warnings about unused arguments
5597 startstring=startstring;
5598
5599 dword section_id;
5600 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5601
5602 if(!f)
5603 {
5604 return false;
5605 }
5606
5607 if(!p_mgetl(&section_id,f))
5608 {
5609 return false;
5610 }
5611
5612 if(section_id==ID_STRINGS)
5613 {
5614 if(readstrings(f, &header)==0)
5615 {
5616 pack_fclose(f);
5617 return true;
5618 }
5619 else
5620 {
5621 pack_fclose(f);
5622 return false;
5623 }
5624 }
5625
5626 pack_fclose(f);
5627 return false;
5628 }
5629
5630 bool load_strings_tsv(const char *path)
5631 {
5632 try
5633 {
5634 parse_strings_tsv(util::read_text_file(path));
5635 }
5636 catch (std::exception& ex)
5637 {
5638 InfoDialog("Import .tsv Error", ex.what()).show();
5639 return false;
5640 }
5641 return true;
5642 }
5643
5644 bool save_pals(const char *path)
5645 {
5646 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5647
5648 if(!f)
5649 {
5650 return false;
5651 }
5652
5653 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)==0)
5654 {
5655 pack_fclose(f);
5656 return true;
5657 }
5658
5659 pack_fclose(f);
5660 return false;
5661 }
5662
5663 bool load_pals(const char *path, int32_t startcset)
5664 {
5665 dword section_id;
5666 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5667
5668 if(!f)
5669 {
5670 return false;
5671 }
5672
5673 if(!p_mgetl(&section_id,f))
5674 {
5675 return false;
5676 }
5677
5678 if(section_id==ID_CSETS)
5679 {
5680 if(readcolordata(f, &QMisc, 0x250, 33, startcset, newerpdTOTAL-startcset)==0)
5681 {
5682 pack_fclose(f);
5683 loadlvlpal(Color);
5684 return true;
5685 }
5686 else
5687 {
5688 pack_fclose(f);
5689 return false;
5690 }
5691 }
5692
5693 return false;
5694 }
5695
5696 int32_t writeguys(PACKFILE *f, zquestheader *Header);
5697 bool save_guys(const char *path)
5698 {
5699 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5700
5701 if(!f)
5702 {
5703 return false;
5704 }
5705
5706 /*
5707 int32_t id = ID_GUYS;
5708 if(!p_mputl(id,f))
5709 {
5710 return false;
5711 }
5712 */
5713
5714 zquestheader h;
5715 h.zelda_version = 0x250;
5716 h.build = 21;
5717
5718 if(writeguys(f, &h)==0)
5719 {
5720 pack_fclose(f);
5721 return true;
5722 }
5723
5724 pack_fclose(f);
5725 return false;
5726 }
5727
5728 bool load_guys(const char *path)
5729 {
5730 dword section_id;
5731 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5732
5733 if(!f)
5734 {
5735 return false;
5736 }
5737
5738 if(!p_mgetl(&section_id,f))
5739 {
5740 pack_fclose(f);
5741 return false;
5742 }
5743
5744 zquestheader h;
5745 h.zelda_version = 0x250;
5746 h.build = 21;
5747
5748 if(section_id==ID_GUYS)
5749 {
5750 if(readguys(f, &h)==0)
5751 {
5752 pack_fclose(f);
5753 return true;
5754 }
5755 }
5756
5757 pack_fclose(f);
5758 return false;
5759 }
5760
5761
5762 //int32_t writeguys(PACKFILE *f, zquestheader *Header);
5763 bool save_combo_alias(const char *path)
5764 {
5765 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5766
5767 if(!f)
5768 {
5769 return false;
5770 }
5771
5772 zquestheader h;
5773 h.zelda_version = 0x250;
5774 h.build = 21;
5775
5776 if(writecomboaliases(f, 0, 0)==0)
5777 {
5778 pack_fclose(f);
5779 return true;
5780 }
5781
5782 pack_fclose(f);
5783 return false;
5784 }
5785
5786 bool load_combo_alias(const char *path)
5787 {
5788 dword section_id;
5789 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5790
5791 if(!f)
5792 {
5793 return false;
5794 }
5795
5796 if(!p_mgetl(&section_id,f))
5797 {
5798 pack_fclose(f);
5799 return false;
5800 }
5801
5802 zquestheader h;
5803 h.zelda_version = 0x250;
5804 h.build = 21;
5805
5806 if(section_id==ID_COMBOALIASES)
5807 {
5808 if(readcomboaliases(f, &h, 0, 0)==0)
5809 {
5810 pack_fclose(f);
5811 return true;
5812 }
5813 }
5814
5815 pack_fclose(f);
5816 return false;
5817 }
5818
5819 bool load_zgp(const char *path)
5820 {
5821 dword section_id;
5822 word section_version;
5823 PACKFILE *f=pack_fopen_password(path,F_READ,"");
5824
5825 if(!f)
5826 return false;
5827
5828 if(!p_mgetl(&section_id,f))
5829 {
5830 pack_fclose(f);
5831 return false;
5832 }
5833
5834 if(section_id!=ID_GRAPHICSPACK)
5835 {
5836 pack_fclose(f);
5837 return false;
5838 }
5839
5840 //section version info
5841 if(!p_igetw(&section_version,f))
5842 {
5843 return 2;
5844 }
5845
5846 if(!read_deprecated_section_cversion(f))
5847 {
5848 return 3;
5849 }
5850
5851 //tiles
5852 if(!p_mgetl(&section_id,f))
5853 {
5854 pack_fclose(f);
5855 return false;
5856 }
5857
5858 if(section_id==ID_TILES)
5859 {
5860 if(readtiles(f, newtilebuf, NULL, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES, false)!=0)
5861 {
5862 pack_fclose(f);
5863 init_tiles(true, &header);
5864 return false;
5865 }
5866 }
5867 else
5868 {
5869 pack_fclose(f);
5870 return false;
5871 }
5872
5873 //combos
5874 if(!p_mgetl(&section_id,f))
5875 {
5876 pack_fclose(f);
5877 return false;
5878 }
5879
5880 if(section_id==ID_COMBOS)
5881 {
5882 if(readcombos(f, NULL, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
5883 {
5884 pack_fclose(f);
5885 return false;
5886 }
5887 }
5888 else
5889 {
5890 pack_fclose(f);
5891 return false;
5892 }
5893
5894 //palettes
5895 if(!p_mgetl(&section_id,f))
5896 {
5897 pack_fclose(f);
5898 return false;
5899 }
5900
5901 if(section_id==ID_CSETS)
5902 {
5903 if(readcolordata(f, &QMisc, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
5904 {
5905 pack_fclose(f);
5906 return false;
5907 }
5908 }
5909 else
5910 {
5911 pack_fclose(f);
5912 return false;
5913 }
5914
5915 //items
5916 if(!p_mgetl(&section_id,f))
5917 {
5918 pack_fclose(f);
5919 return false;
5920 }
5921
5922 if(section_id==ID_ITEMS)
5923 {
5924 if(readitems(f, ZELDA_VERSION, VERSION_BUILD)!=0)
5925 {
5926 pack_fclose(f);
5927 return false;
5928 }
5929 }
5930 else
5931 {
5932 pack_fclose(f);
5933 return false;
5934 }
5935
5936 //weapons
5937 if(!p_mgetl(&section_id,f))
5938 {
5939 pack_fclose(f);
5940 return false;
5941 }
5942
5943 if(section_id==ID_WEAPONS)
5944 {
5945 if(readweapons(f, &header)!=0)
5946 {
5947 pack_fclose(f);
5948 return false;
5949 }
5950 }
5951 else
5952 {
5953 pack_fclose(f);
5954 return false;
5955 }
5956
5957 //read the triforce pieces info and make sure it worked
5958 //really do this?
5959
5960 //read the game icons info and make sure it worked
5961 if(!p_mgetl(&section_id,f))
5962 {
5963 pack_fclose(f);
5964 return false;
5965 }
5966
5967 if(section_id==ID_ICONS)
5968 {
5969 if(readgameicons(f, &header, &QMisc)!=0)
5970 {
5971 pack_fclose(f);
5972 return false;
5973 }
5974 }
5975 else
5976 {
5977 pack_fclose(f);
5978 return false;
5979 }
5980
5981 //read the misc colors info and map styles info and make sure it worked
5982 if(!p_mgetl(&section_id,f))
5983 {
5984 pack_fclose(f);
5985 return false;
5986 }
5987
5988 if(section_id==ID_COLORS)
5989 {
5990 if(readmisccolors(f, &header, &QMisc)!=0)
5991 {
5992 pack_fclose(f);
5993 return false;
5994 }
5995 }
5996 else
5997 {
5998 pack_fclose(f);
5999 return false;
6000 }
6001
6002 //read the door combo sets and make sure it worked
6003 if(!p_mgetl(&section_id,f))
6004 {
6005 pack_fclose(f);
6006 return false;
6007 }
6008
6009 if(section_id==ID_DOORS)
6010 {
6011 if(readdoorcombosets(f, &header)!=0)
6012 {
6013 pack_fclose(f);
6014 return false;
6015 }
6016 }
6017 else
6018 {
6019 pack_fclose(f);
6020 return false;
6021 }
6022
6023 //read the template screens and make sure it worked
6024 //really do this?
6025
6026 //yay! it worked! close the file and say everything was ok.
6027 loadlvlpal(Color);
6028 setup_combo_animations();
6029 setup_combo_animations2();
6030 pack_fclose(f);
6031 return true;
6032 }
6033
6034 bool save_zgp(const char *path)
6035 {
6036 reset_combo_animations();
6037 reset_combo_animations2();
6038
6039 //open the file
6040 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6041
6042 if(!f)
6043 return false;
6044
6045 dword section_id=ID_GRAPHICSPACK;
6046 dword section_version=V_GRAPHICSPACK;
6047
6048 //section id
6049 if(!p_mputl(section_id,f))
6050 {
6051 return 1;
6052 }
6053
6054 //section version info
6055 if(!p_iputw(section_version,f))
6056 {
6057 return 2;
6058 }
6059
6060 if(!write_deprecated_section_cversion(section_version,f))
6061 {
6062 return 3;
6063 }
6064
6065 //tiles
6066 if(writetiles(f, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES)!=0)
6067 {
6068 pack_fclose(f);
6069 return false;
6070 }
6071
6072 //combos
6073 if(writecombos(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
6074 {
6075 pack_fclose(f);
6076 return false;
6077 }
6078
6079 //palettes
6080 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
6081 {
6082 pack_fclose(f);
6083 return false;
6084 }
6085
6086 //items
6087 if(writeitems(f, &header)!=0)
6088 {
6089 pack_fclose(f);
6090 return false;
6091 }
6092
6093 //weapons
6094 if(writeweapons(f, &header)!=0)
6095 {
6096 pack_fclose(f);
6097 return false;
6098 }
6099
6100 //write the triforce pieces info and make sure it worked
6101 //really do this?
6102
6103 //write the game icons info and make sure it worked
6104 if(writegameicons(f, &header)!=0)
6105 {
6106 pack_fclose(f);
6107 return false;
6108 }
6109
6110 //write the misc colors info and map styles info and make sure it worked
6111 if(writemisccolors(f, &header)!=0)
6112 {
6113 pack_fclose(f);
6114 return false;
6115 }
6116
6117 //write the door combo sets and make sure it worked
6118 if(writedoorcombosets(f, &header)!=0)
6119 {
6120 pack_fclose(f);
6121 return false;
6122 }
6123
6124 //write the template screens and make sure it worked
6125 //really do this?
6126
6127 pack_fclose(f);
6128 return true;
6129 }
6130
6131 bool save_subscreen(const char *path, ZCSubscreen const& savefrom)
6132 {
6133 //open the file
6134 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6135
6136 if(!f)
6137 return false;
6138
6139 dword section_id=ID_SUBSCREEN;
6140 dword s_version=V_SUBSCREEN;
6141
6142 if(!p_mputl(section_id,f))
6143 {
6144 pack_fclose(f);
6145 return false;
6146 }
6147
6148 if(!p_iputw(s_version,f))
6149 {
6150 pack_fclose(f);
6151 return false;
6152 }
6153
6154 if(!write_deprecated_section_cversion(s_version,f))
6155 {
6156 pack_fclose(f);
6157 return false;
6158 }
6159
6160 if(savefrom.write(f))
6161 {
6162 pack_fclose(f);
6163 return false;
6164 }
6165
6166 pack_fclose(f);
6167 return true;
6168 }
6169
6170 bool load_subscreen(const char *path, ZCSubscreen& loadto)
6171 {
6172 //open the file
6173 PACKFILE *f=pack_fopen_password(path,F_READ, "");
6174
6175 if(!f)
6176 return false;
6177
6178 dword section_id;
6179 dword s_version;
6180
6181 if(!p_mgetl(&section_id,f))
6182 {
6183 pack_fclose(f);
6184 return false;
6185 }
6186
6187 if(section_id!=ID_SUBSCREEN)
6188 {
6189 pack_fclose(f);
6190 return false;
6191 }
6192
6193 if(!p_igetw(&s_version,f))
6194 {
6195 pack_fclose(f);
6196 return false;
6197 }
6198
6199 if (s_version > V_SUBSCREEN)
6200 return qe_version;
6201
6202 if(!read_deprecated_section_cversion(f))
6203 {
6204 pack_fclose(f);
6205 return false;
6206 }
6207
6208 if(s_version < 8)
6209 {
6210 subscreen_group g;
6211 memset(&g,0,sizeof(subscreen_group));
6212 if(read_one_old_subscreen(f,&g,s_version)!=0)
6213 {
6214 pack_fclose(f);
6215 return false;
6216 }
6217 if(g.ss_type != loadto.sub_type)
6218 {
6219 pack_fclose(f);
6220 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6221 subscr_names[g.ss_type], subscr_names[loadto.sub_type]));
6222 return false;
6223 }
6224 loadto.clear();
6225 if(g.objects[0].type != ssoNULL)
6226 loadto.load_old(g);
6227 }
6228 else
6229 {
6230 ZCSubscreen tmp = ZCSubscreen();
6231 if (tmp.read(f, s_version))
6232 {
6233 pack_fclose(f);
6234 return false;
6235 }
6236 if(tmp.sub_type != loadto.sub_type)
6237 {
6238 pack_fclose(f);
6239 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6240 subscr_names[tmp.sub_type], subscr_names[loadto.sub_type]));
6241 return false;
6242 }
6243 loadto.clear();
6244 loadto = tmp;
6245 }
6246
6247 pack_fclose(f);
6248 return true;
6249 }
6250
6251 bool setMapCount2(int32_t c)
6252 {
6253 int32_t oldmapcount=map_count;
6254 int32_t cur_map=Map.getCurrMap();
6255
6256 bound(c,1,MAXMAPS);
6257 map_count=c;
6258
6259 try
6260 {
6261 TheMaps.resize(c*MAPSCRS);
6262 Map.force_refr_pointer();
6263 map_infos.resize(c);
6264 }
6265 catch(...)
6266 {
6267 jwin_alert("Error","Failed to change map count.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
6268 return false;
6269 }
6270
6271 bound(cur_map,0,c-1);
6272 if(map_count>oldmapcount)
6273 {
6274 for(int32_t mc=oldmapcount; mc<map_count; mc++)
6275 {
6276 // copy the default palette to the new maps
6277 map_infos[mc].autopalette = map_infos[cur_map].autopalette;
6278
6279 Map.setCurrMap(mc);
6280 for(int32_t ms=0; ms<MAPSCRS; ms++)
6281 Map.clearscr(ms);
6282 }
6283 Map.setCurrMap(cur_map);
6284 }
6285 else
6286 {
6287 Map.setCurrMap(cur_map);
6288 if(!layers_valid(Map.CurrScr()))
6289 fix_layers(Map.CurrScr(), false);
6290
6291 for(int32_t i=0; i<MAXDMAPS; i++)
6292 {
6293 if(DMaps[i].map>=map_count)
6294 {
6295 DMaps[i].map=map_count-1;
6296 }
6297 }
6298 }
6299
6300 return true;
6301 }
6302
6303 extern BITMAP *bmap;
6304
6305 static bool loading_file_new = false;
6306 int32_t init_quest(std::string tileset_path)
6307 {
6308 if (tileset_path.empty())
6309 tileset_path = DEFAULT_TILESET;
6310
6311 loading_file_new = true;
6312 load_quest(tileset_path.c_str());
6313 loading_file_new = false;
6314
6315 set_window_title("ZC Editor - Untitled Quest");
6316 zinit.last_map = 0;
6317 zinit.last_screen = 0;
6318
6319 if(bmap != NULL)
6320 {
6321 destroy_bitmap(bmap);
6322 bmap=NULL;
6323 }
6324
6325 return 0;
6326 }
6327
6328 void set_questpwd(std::string_view pwd, bool use_keyfile)
6329 {
6330 header.use_keyfile=use_keyfile;
6331
6332 // string_view actually has some quirks that make it less than ideal here.
6333 // It'd probably be best to replace it, but this works for now.
6334 memset(header.password, 0, 256);
6335 strcpy(header.password, pwd.data());
6336 header.dirty_password=true;
6337
6338 cvs_MD5Context ctx;
6339 cvs_MD5Init(&ctx);
6340 cvs_MD5Update(&ctx, (const uint8_t*)header.password, strlen(header.password));
6341 cvs_MD5Final(header.pwd_hash, &ctx);
6342 }
6343
6344
6345 bool is_null_pwd_hash(uint8_t *pwd_hash)
6346 {
6347 cvs_MD5Context ctx;
6348 uint8_t md5sum[16];
6349 char pwd[2]="";
6350
6351 cvs_MD5Init(&ctx);
6352 cvs_MD5Update(&ctx, (const uint8_t*)pwd, (unsigned)strlen(pwd));
6353 cvs_MD5Final(md5sum, &ctx);
6354
6355 return (memcmp(md5sum,pwd_hash,16)==0);
6356 }
6357
6358 static DIALOG pwd_dlg[] =
6359 {
6360 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
6361 { jwin_win_proc, 0, 0, 224+22+1, 88+10+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "Requires Authorization", NULL, NULL },
6362 { jwin_text_proc, 16, 28, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "File name:", NULL, NULL },
6363 // 2 (filename)
6364 { jwin_text_proc, 72, 28, 128, 8, vc(11), vc(1), 0, 0, 24, 0, NULL, NULL, NULL },
6365 { jwin_text_proc, 16, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, (void *) "Challenge:", NULL, NULL },
6366 // 4 (challenge hash)
6367 { jwin_text_proc, 72, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6368 { jwin_text_proc, 16, 42+10, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Password:", NULL, NULL },
6369 // 6 (password)
6370 { jwin_edit_proc, 72, 38+10, 120+39, 16, vc(12), vc(1), 0, 0, 255, 0, NULL, NULL, NULL },
6371 { jwin_button_proc, 42, 62+10, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6372 { jwin_button_proc, 122, 62+10, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6373 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6374 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6375 };
6376
6377 int32_t reverse_string(char* str)
6378 {
6379
6380 if(NULL==str)
6381 {
6382 return -1; //no string
6383 }
6384
6385 int32_t l=(int32_t)strlen(str)-1; //get the string length
6386
6387 if(1==l)
6388 {
6389 return 1;
6390 }
6391
6392 char c;
6393
6394 for(int32_t x=0; x < l; x++,l--)
6395 {
6396 c = str[x];
6397 str[x] = str[l];
6398 str[l] = c;
6399 }
6400
6401 return 0;
6402 }
6403
6404 #ifdef __GNUC__
6405 #pragma GCC diagnostic push
6406 #pragma GCC diagnostic ignored "-Wunreachable-code"
6407 #endif
6408
6409 11 int32_t quest_access(const char *filename, zquestheader *hdr)
6410 {
6411
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (is_headless())
6412 11 return 1;
6413
6414 #ifdef __EMSCRIPTEN__
6415 return 1;
6416 #endif
6417
6418 //Protection against compiling a release version with password protection off.
6419 static bool passguard = false;
6420
6421 #if ( !(defined _DEBUG) || (defined _RELEASE || defined NDEBUG || defined _NDEBUG) )
6422 #define MUST_HAVE_PASSWORD
6423 passguard = true;
6424 #endif
6425
6426 #if ( !(defined MUST_HAVE_PASSWORD) || defined _NPASS )
6427 #if (defined _MSC_VER || defined _NPASS)
6428 return 1;
6429 #endif
6430 #endif
6431 if(devpwd()) return 1;
6432
6433 char hash_string[33];
6434
6435 if((get_debug() && (!(CHECK_CTRL_CMD))) || is_null_pwd_hash(hdr->pwd_hash))
6436 {
6437 return 1;
6438 }
6439
6440 if(check_keyfiles(filename, {KEYFILE_MASTER,KEYFILE_ZPWD}, hdr))
6441 return true;
6442
6443 pwd_dlg[0].dp2=get_zc_font(font_lfont);
6444 pwd_dlg[2].dp=get_filename(filename);
6445 cvs_MD5Context ctx;
6446 uint8_t md5sum[16]={0};
6447 char response[33]="";
6448 char prompt[256]="";
6449
6450 memcpy(md5sum, hdr->pwd_hash, 16);
6451
6452 for(int32_t i=0; i<300; ++i)
6453 {
6454 for(int32_t j=0; j<16; ++j)
6455 {
6456 sprintf(response+j*2, "%02x", md5sum[j]);
6457 }
6458
6459 if(i&1)
6460 {
6461 reverse_string(response);
6462 }
6463
6464 if(i==149)
6465 {
6466 strcpy(hash_string, response);
6467 }
6468
6469 cvs_MD5Init(&ctx);
6470 cvs_MD5Update(&ctx, (const uint8_t*)response, (unsigned)strlen(response));
6471 cvs_MD5Final(md5sum, &ctx);
6472 }
6473
6474 pwd_dlg[4].dp=hash_string;
6475
6476 if(get_debug() && (CHECK_CTRL_CMD)) //...what is this doing?
6477 {
6478 sprintf(prompt,"%s",response);
6479 }
6480
6481 pwd_dlg[6].dp=prompt;
6482
6483 large_dialog(pwd_dlg);
6484
6485 int32_t cancel = do_zqdialog(pwd_dlg,6);
6486
6487 if(cancel == 8)
6488 return 2;
6489
6490 bool ret=check_questpwd(hdr, prompt);
6491
6492 if(!ret)
6493 {
6494 ret=(strcmp(response,prompt)==0);
6495 }
6496 return ret ? 1 : 0;
6497 11 }
6498
6499 void set_rules(byte* newrules);
6500 11 void popup_bugfix_dlg(const char* cfg, byte* dest_qrs)
6501 {
6502 11 bool dont_show_again = zc_get_config("zquest",cfg,0);
6503
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11 times.
11 if(!dont_show_again && hasCompatRulesEnabled())
6504 {
6505
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
33 AlertDialog("Apply New Bugfixes",
6506
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 "New bugfixes found that can be applied to this quest!"
6507 "\nWould you like to apply them?"
6508 "\n(Applies 'Bugfix' rule template, un-checking compat rules)",
6509 11 [&](bool ret,bool dsa)
6510 {
6511 if(ret)
6512 {
6513 applyRuleTemplate(ruletemplateFixCompat,dest_qrs);
6514 }
6515 if(dsa)
6516 {
6517 zc_set_config("zquest",cfg,1);
6518 }
6519 },
6520
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 "Yes","No",
6521 0,false, //timeout - none
6522 true //"Don't show this again"
6523
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 ).show();
6524 11 }
6525 11 }
6526
6527 #ifdef __GNUC__
6528 #pragma GCC diagnostic pop
6529 #endif
6530
6531 11 int32_t load_quest(const char *filename, bool show_progress)
6532 {
6533 11 zq_freeze_all_rti();
6534
6535 char buf[2048];
6536 byte skip_flags[4];
6537
6538 11 dword tileset_flags = 0;
6539
2/2
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 11 times.
55 for(int32_t i=0; i<4; ++i)
6540 {
6541 44 skip_flags[i]=0;
6542 44 }
6543
2/2
✓ Branch 0 taken 7634 times.
✓ Branch 1 taken 11 times.
7645 for(int32_t i=0; i<qr_MAX; i++)
6544 7634 set_qr(i,0);
6545 11 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,show_progress,skip_flags,1,true,0,tileset_flags);
6546
6547
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(ret!=qe_OK)
6548 {
6549 init_quest(DEFAULT_TILESET);
6550 }
6551 else
6552 {
6553 11 int32_t accessret = quest_access(filename, &header);
6554
6555
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(accessret != 1)
6556 {
6557 init_quest(DEFAULT_TILESET);
6558
6559 if(accessret == 0)
6560 ret=qe_pwd;
6561 else
6562 ret=qe_cancel;
6563 }
6564 else
6565 {
6566 11 Map.clear();
6567
6568
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 std::string qst_cfg_header = qst_cfg_header_from_path(filename);
6569
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 int view_size = zc_get_config(qst_cfg_header.c_str(), "zoom_num_screens", 1);
6570
6571
4/8
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 11 times.
✗ Branch 7 not taken.
11 Map.setCursor(MapCursor{
6572
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 .map = vbound(zinit.last_map, 0, map_count - 1),
6573 11 .screen = zinit.last_screen,
6574 11 .viewscr = zinit.last_screen,
6575 11 .size = view_size,
6576 });
6577
6578 extern int32_t current_mappage;
6579 11 current_mappage = 0;
6580 11 bool found_default = false;
6581
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 83 times.
92 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6582 {
6583 83 auto &pg = map_page[q];
6584
4/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 2 times.
83 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6585 {
6586 2 current_mappage = q;
6587 2 break;
6588 }
6589
4/8
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
81 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6590 72 continue;
6591 else
6592 {
6593 9 current_mappage = q;
6594 9 found_default = true;
6595 }
6596 9 }
6597
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 refresh(rALL);
6598
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 refresh_pal();
6599
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 set_rules(quest_rules);
6600 11 saved = true;
6601
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
11 if(!(loading_file_new && zc_get_config("zquest","auto_filenew_bugfixes",1)))
6602
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 popup_bugfix_dlg("dsa_compatrule",nullptr);
6603
6604
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(bmap != NULL)
6605 {
6606 destroy_bitmap(bmap);
6607 bmap=NULL;
6608 }
6609
6610
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (show_progress)
6611 {
6612 sprintf(buf,"ZC Editor - [%s]", get_filename(filename));
6613 set_window_title(buf);
6614 }
6615 11 }
6616 }
6617
6618 11 Map.ClearCommandHistory();
6619
6620
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (!is_headless())
6621 {
6622 void load_size_poses();
6623 load_size_poses();
6624 }
6625
6626 11 return ret;
6627 }
6628
6629 int32_t load_tileset(const char *filename, dword tsetflags)
6630 {
6631 zq_freeze_all_rti();
6632
6633 byte skip_flags[4];
6634
6635 for(int32_t i=0; i<4; ++i)
6636 skip_flags[i]=0;
6637 for(int32_t i=0; i<qr_MAX; i++)
6638 set_qr(i,0);
6639 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,true,skip_flags,1,true,0,tsetflags);
6640
6641 if(ret!=qe_OK)
6642 init_quest(DEFAULT_TILESET);
6643 else
6644 {
6645 if(tsetflags & TILESET_BUGFIX)
6646 applyRuleTemplate(ruletemplateFixCompat);
6647 if(tsetflags & TILESET_SCR_BUGFIX)
6648 applyRuleTemplate(ruletemplateFixZSCompat);
6649
6650 int32_t accessret = quest_access(filename, &header);
6651
6652 if(accessret != 1)
6653 {
6654 init_quest(DEFAULT_TILESET);
6655
6656 if(accessret == 0)
6657 ret=qe_pwd;
6658 else
6659 ret=qe_cancel;
6660 }
6661 else
6662 {
6663 Map.clear();
6664 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6665 Map.setCurrScr(zinit.last_screen);
6666 extern int32_t current_mappage;
6667 current_mappage = 0;
6668 bool found_default = false;
6669 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6670 {
6671 auto &pg = map_page[q];
6672 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6673 {
6674 current_mappage = q;
6675 break;
6676 }
6677 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6678 continue;
6679 else
6680 {
6681 current_mappage = q;
6682 found_default = true;
6683 }
6684 }
6685 refresh(rALL);
6686 refresh_pal();
6687 set_rules(quest_rules);
6688
6689 if(bmap != NULL)
6690 {
6691 destroy_bitmap(bmap);
6692 bmap=NULL;
6693 }
6694
6695 set_window_title("ZC Editor - Untitled Quest");
6696 first_save = saved = false;
6697 memset(filepath,0,255);
6698 memset(temppath,0,255);
6699 }
6700 }
6701
6702 Map.ClearCommandHistory();
6703
6704 return ret;
6705 }
6706
6707 272730 int32_t write_weap_data(weapon_data const& data, PACKFILE* f)
6708 {
6709
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if(!p_iputw(V_WEAP_DATA,f))
6710 new_return(1);
6711
6712
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.flags, f))
6713 new_return(2);
6714
6715
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.moveflags, f))
6716 new_return(3);
6717
6718
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.wflags, f))
6719 new_return(4);
6720
6721
2/2
✓ Branch 0 taken 1363650 times.
✓ Branch 1 taken 272730 times.
1636380 for (int32_t q = 0; q < WPNSPR_MAX; ++q)
6722 {
6723
1/2
✓ Branch 0 taken 1363650 times.
✗ Branch 1 not taken.
1363650 if (!p_putc(data.burnsprs[q], f))
6724 new_return(5);
6725
1/2
✓ Branch 0 taken 1363650 times.
✗ Branch 1 not taken.
1363650 if (!p_putc(data.light_rads[q], f))
6726 new_return(6);
6727 1363650 }
6728
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.glow_shape, f))
6729 new_return(7);
6730
6731
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.override_flags, f))
6732 new_return(8);
6733
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.tilew, f))
6734 new_return(9);
6735
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.tileh, f))
6736 new_return(10);
6737
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hxsz, f))
6738 new_return(11);
6739
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hysz, f))
6740 new_return(12);
6741
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hzsz, f))
6742 new_return(13);
6743
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hxofs, f))
6744 new_return(14);
6745
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hyofs, f))
6746 new_return(15);
6747
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.xofs, f))
6748 new_return(16);
6749
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.yofs, f))
6750 new_return(17);
6751
6752
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputzf(data.step, f))
6753 new_return(18);
6754
6755
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.unblockable, f))
6756 new_return(19);
6757
6758
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.timeout, f))
6759 new_return(20);
6760
6761
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.imitate_weapon, f))
6762 new_return(21);
6763
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.default_defense, f))
6764 new_return(22);
6765
6766
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.lift_level, f))
6767 new_return(23);
6768
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.lift_time, f))
6769 new_return(24);
6770
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputzf(data.lift_height, f))
6771 new_return(25);
6772
6773
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.script, f))
6774 new_return(26);
6775
2/2
✓ Branch 0 taken 2181840 times.
✓ Branch 1 taken 272730 times.
2454570 for(uint q = 0; q < 8; ++q)
6776
1/2
✓ Branch 0 taken 2181840 times.
✗ Branch 1 not taken.
2181840 if(!p_iputl(data.initd[q], f))
6777 new_return(27);
6778
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.pierce_count, f))
6779 new_return(28);
6780 272730 return 0;
6781 }
6782
6783 130 bool write_midi(MIDI *m,PACKFILE *f)
6784 {
6785 int32_t c;
6786
6787
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 130 times.
130 if(!p_mputw(m->divisions,f)) return false;
6788
6789
2/2
✓ Branch 0 taken 4160 times.
✓ Branch 1 taken 130 times.
4290 for(c=0; c<MIDI_TRACKS; c++)
6790 {
6791
1/2
✓ Branch 0 taken 4160 times.
✗ Branch 1 not taken.
4160 if(!p_mputl(m->track[c].len,f)) return false;
6792
6793
2/2
✓ Branch 0 taken 2896 times.
✓ Branch 1 taken 1264 times.
4160 if(m->track[c].len > 0)
6794 {
6795
1/2
✓ Branch 0 taken 1264 times.
✗ Branch 1 not taken.
1264 if(!pfwrite(m->track[c].data,m->track[c].len,f))
6796 return false;
6797 1264 }
6798 4160 }
6799
6800 130 return true;
6801 130 }
6802
6803 9 int32_t writeheader(PACKFILE *f, zquestheader *Header)
6804 {
6805 9 dword section_id=ID_HEADER;
6806 9 dword section_version=V_HEADER;
6807 9 dword section_size=0;
6808
6809 //file header string
6810
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!pfwrite(Header->id_str,sizeof(Header->id_str),f))
6811 {
6812 new_return(1);
6813 }
6814
6815 //section id
6816
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
6817 {
6818 new_return(2);
6819 }
6820
6821 //section version info
6822
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
6823 {
6824 new_return(3);
6825 }
6826
6827
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
6828 {
6829 new_return(4);
6830 }
6831
6832
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
6833 {
6834 18 fake_pack_writing=(writecycle==0);
6835
6836 //section size
6837
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
6838 {
6839 new_return(5);
6840 }
6841
6842 18 writesize=0;
6843
6844 //finally... section data
6845
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(Header->zelda_version,f))
6846 {
6847 new_return(6);
6848 }
6849
6850
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->build,f))
6851 {
6852 new_return(7);
6853 }
6854
6855
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->pwd_hash,sizeof(Header->pwd_hash),f))
6856 {
6857 new_return(8);
6858 }
6859
6860
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(Header->internal,f))
6861 {
6862 new_return(10);
6863 }
6864
6865
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->quest_number,f))
6866 {
6867 new_return(11);
6868 }
6869
6870
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->version,16,f))
6871 {
6872 new_return(12);
6873 }
6874
6875
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->minver,16,f))
6876 {
6877 new_return(13);
6878 }
6879
6880
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->title,sizeof(Header->title),f))
6881 {
6882 new_return(14);
6883 }
6884
6885
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->author,sizeof(Header->author),f))
6886 {
6887 new_return(15);
6888 }
6889
6890
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->use_keyfile,f))
6891 {
6892 new_return(16);
6893 }
6894
6895
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->data_flags,sizeof(Header->data_flags),f))
6896 {
6897 new_return(17);
6898 }
6899
6900
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->templatepath,sizeof(Header->templatepath),f))
6901 {
6902 new_return(19);
6903 }
6904
6905
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(0,f)) //why are we doing this?
6906 //this is for map count, it seems. -Z
6907 {
6908 new_return(20);
6909 }
6910
6911 18 auto version = getVersion();
6912
6913
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(version.major,f))
6914 {
6915 new_return(21);
6916 }
6917
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(version.minor,f))
6918 {
6919 new_return(22);
6920 }
6921
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(version.patch,f))
6922 {
6923 new_return(23);
6924 }
6925 // Fourth component is deprecated.
6926
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6927 {
6928 new_return(24);
6929 }
6930
6931 // Numerous prerelease stages is deprecated.
6932
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6933 {
6934 new_return(25);
6935 }
6936
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6937 {
6938 new_return(26);
6939 }
6940
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6941 {
6942 new_return(27);
6943 }
6944
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6945 {
6946 new_return(28);
6947 }
6948
6949
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(BUILDTM_YEAR,f))
6950 {
6951 new_return(29);
6952 }
6953
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_MONTH,f))
6954 {
6955 new_return(30);
6956 }
6957
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_DAY,f))
6958 {
6959 new_return(31);
6960 }
6961
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_HOUR,f))
6962 {
6963 new_return(32);
6964 }
6965
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_MINUTE,f))
6966 {
6967 new_return(33);
6968 }
6969
6970 // This is no longer set to anything.
6971 const char* tempsig[256];
6972 18 memset(tempsig, 0, 256);
6973
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempsig,256,f))
6974 {
6975 new_return(34);
6976 }
6977
6978 char tempcompilersig[256];
6979 18 memset(tempcompilersig, 0, 256);
6980 18 strcpy(tempcompilersig, COMPILER_NAME);
6981
6982
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempcompilersig,256,f))
6983 {
6984 new_return(35);
6985 }
6986
6987 char tempcompilerversion[256];
6988 18 memset(tempcompilerversion, 0, 256);
6989 #ifdef _MSC_VER
6990 zc_itoa(_MSC_VER,tempcompilerversion,10);
6991 #else
6992 18 strcpy(tempcompilerversion, COMPILER_VERSION);
6993 #endif
6994
6995
6996
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempcompilerversion,256,f))
6997 {
6998 new_return(36);
6999 }
7000
7001
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite("ZQuest Classic",1024,f))
7002 {
7003 new_return(37);
7004 }
7005
7006 // V_ZC_COMPILERSIG - a deprecated version field.
7007
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(1,f))
7008 {
7009 new_return(38);
7010 }
7011 #ifdef _MSC_VER
7012 if(!p_iputl((_MSC_VER / 100),f))
7013 {
7014 new_return(39);
7015 }
7016 #else
7017
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_FIRST,f))
7018 {
7019 new_return(39);
7020 }
7021 #endif
7022
7023
7024
7025 #ifdef _MSC_VER
7026 if(!p_iputl((_MSC_VER % 100),f))
7027 {
7028 new_return(41);
7029 }
7030 #else
7031
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_SECOND,f))
7032 {
7033 new_return(41);
7034 }
7035 #endif
7036
7037 #ifdef _MSC_VER
7038 # if _MSC_VER >= 1400
7039 if(!p_iputl((_MSC_FULL_VER % 100000),f))
7040 {
7041 new_return(40);
7042 }
7043 # else
7044 if(!p_iputl((_MSC_FULL_VER % 10000),f))
7045 {
7046 new_return(40);
7047 }
7048 #endif
7049 #else
7050
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_THIRD,f))
7051 {
7052 new_return(40);
7053 }
7054 #endif
7055
7056 #ifdef _MSC_VER
7057 if(!p_iputl((_MSC_BUILD),f))
7058 {
7059 new_return(42);
7060 }
7061 #else
7062
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_FOURTH,f))
7063 {
7064 new_return(42);
7065 }
7066 #endif
7067
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(0,f)) //was V_ZC_DEVSIG, no longer used
7068 {
7069 new_return(43);
7070 }
7071
7072 // Modules were removed (replaced by zinfo).
7073 char tempmodulename[1024];
7074 18 memset(tempmodulename, 0, 1024);
7075
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempmodulename,1024,f))
7076 {
7077 new_return(44);
7078 }
7079
7080 char tempdate[256];
7081 18 memset(tempdate, 0, 256);
7082 18 strcpy(tempdate, __DATE__);
7083
7084
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempdate,256,f))
7085 {
7086 new_return(45);
7087 }
7088 char temptime[256];
7089 18 memset(temptime, 0, 256);
7090 18 strcpy(temptime, __TIME__);
7091
7092
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&temptime,256,f))
7093 {
7094 new_return(46);
7095 }
7096
7097
7098 char temptimezone[6];
7099 18 memset(temptimezone, 0, 6);
7100 18 strcpy(temptimezone, __TIMEZONE__);
7101
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&temptimezone,6,f))
7102 {
7103 new_return(47);
7104 }
7105
7106
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->external_zinfo ? 1 : 0, f))
7107 {
7108 new_return(48);
7109 }
7110
7111
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(isStableRelease() ? 0 : 1, f))
7112 {
7113 new_return(49);
7114 }
7115
7116
3/6
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
18 if(!p_putcstr(version.version_string, f))
7117 {
7118 new_return(50);
7119 }
7120
7121
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7122 {
7123 9 section_size=writesize;
7124 9 }
7125 18 }
7126
7127
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7128 {
7129 char ebuf[80];
7130 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7131 jwin_alert("Error: writeheader()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7132 }
7133
7134 9 new_return(0);
7135 }
7136
7137 9 int32_t writerules(PACKFILE *f, zquestheader *Header)
7138 {
7139 //these are here to bypass compiler warnings about unused arguments
7140 9 Header=Header;
7141
7142 9 dword section_id=ID_RULES;
7143 9 dword section_version=V_RULES;
7144 9 dword section_size=0;
7145
7146 //section id
7147
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7148 {
7149 new_return(1);
7150 }
7151
7152 //section version info
7153
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7154 {
7155 new_return(2);
7156 }
7157
7158
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
7159 {
7160 new_return(3);
7161 }
7162
7163
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!p_iputl(V_COMPATRULE,f))
7164 {
7165 new_return(6);
7166 }
7167
7168
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7169 {
7170 18 fake_pack_writing=(writecycle==0);
7171
7172 //section size
7173
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7174 {
7175 new_return(4);
7176 }
7177
7178 18 writesize=0;
7179
7180 //finally... section data
7181
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(quest_rules,QUESTRULES_NEW_SIZE,f))
7182 {
7183 new_return(5);
7184 }
7185
7186
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7187 {
7188 9 section_size=writesize;
7189 9 }
7190 18 }
7191
7192
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7193 {
7194 char ebuf[80];
7195 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7196 jwin_alert("Error: writerules()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7197 }
7198
7199 9 new_return(0);
7200 }
7201
7202
7203 9 int32_t writedoorcombosets(PACKFILE *f, zquestheader *Header)
7204 {
7205 //these are here to bypass compiler warnings about unused arguments
7206 9 Header=Header;
7207
7208 9 dword section_id=ID_DOORS;
7209 9 dword section_version=V_DOORS;
7210 9 dword section_size=0;
7211
7212 //section id
7213
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7214 {
7215 new_return(1);
7216 }
7217
7218 //section version info
7219
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7220 {
7221 new_return(2);
7222 }
7223
7224
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7225 {
7226 new_return(3);
7227 }
7228
7229
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7230 {
7231 18 fake_pack_writing=(writecycle==0);
7232
7233 //section size
7234
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7235 {
7236 new_return(4);
7237 }
7238
7239 18 writesize=0;
7240
7241 //finally... section data
7242
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(door_combo_set_count,f))
7243 {
7244 new_return(5);
7245 }
7246
7247
2/2
✓ Branch 0 taken 320 times.
✓ Branch 1 taken 18 times.
338 for(int32_t i=0; i<door_combo_set_count; i++)
7248 {
7249 //name
7250 char name[21];
7251 320 memset(name, 21, (char)0);
7252 320 strcpy(name, DoorComboSetNames[i].c_str());
7253
1/2
✓ Branch 0 taken 320 times.
✗ Branch 1 not taken.
320 if(!pfwrite(name,sizeof(name),f))
7254 {
7255 new_return(6);
7256 }
7257
7258 //up door
7259
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7260 {
7261
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7262 {
7263
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_iputw(DoorComboSets[i].doorcombo_u[j][k],f))
7264 {
7265 new_return(7);
7266 }
7267 11520 }
7268 2880 }
7269
7270
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7271 {
7272
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7273 {
7274
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_putc(DoorComboSets[i].doorcset_u[j][k],f))
7275 {
7276 new_return(8);
7277 }
7278 11520 }
7279 2880 }
7280
7281 //down door
7282
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7283 {
7284
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7285 {
7286
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_iputw(DoorComboSets[i].doorcombo_d[j][k],f))
7287 {
7288 new_return(9);
7289 }
7290 11520 }
7291 2880 }
7292
7293
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7294 {
7295
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7296 {
7297
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_putc(DoorComboSets[i].doorcset_d[j][k],f))
7298 {
7299 new_return(10);
7300 }
7301 11520 }
7302 2880 }
7303
7304
7305 //left door
7306
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7307 {
7308
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7309 {
7310
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_iputw(DoorComboSets[i].doorcombo_l[j][k],f))
7311
7312 {
7313 new_return(11);
7314 }
7315 17280 }
7316 2880 }
7317
7318
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7319 {
7320
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7321 {
7322
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_putc(DoorComboSets[i].doorcset_l[j][k],f))
7323 {
7324 new_return(12);
7325 }
7326 17280 }
7327 2880 }
7328
7329 //right door
7330
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7331 {
7332
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7333 {
7334
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_iputw(DoorComboSets[i].doorcombo_r[j][k],f))
7335 {
7336 new_return(13);
7337 }
7338 17280 }
7339 2880 }
7340
7341
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7342 {
7343
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7344 {
7345
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_putc(DoorComboSets[i].doorcset_r[j][k],f))
7346 {
7347 new_return(14);
7348 }
7349 17280 }
7350 2880 }
7351
7352
7353 //up bomb rubble
7354
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7355 {
7356
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_iputw(DoorComboSets[i].bombdoorcombo_u[j],f))
7357 {
7358 new_return(15);
7359 }
7360 640 }
7361
7362
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7363 {
7364
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].bombdoorcset_u[j],f))
7365 {
7366 new_return(16);
7367 }
7368 640 }
7369
7370 //down bomb rubble
7371
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7372 {
7373
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_iputw(DoorComboSets[i].bombdoorcombo_d[j],f))
7374 {
7375 new_return(17);
7376 }
7377 640 }
7378
7379
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7380 {
7381
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].bombdoorcset_d[j],f))
7382 {
7383 new_return(18);
7384 }
7385 640 }
7386
7387 //left bomb rubble
7388
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7389 {
7390
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_iputw(DoorComboSets[i].bombdoorcombo_l[j],f))
7391 {
7392 new_return(19);
7393 }
7394 960 }
7395
7396
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7397 {
7398
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_putc(DoorComboSets[i].bombdoorcset_l[j],f))
7399 {
7400 new_return(20);
7401 }
7402 960 }
7403
7404 //right bomb rubble
7405
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7406 {
7407
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_iputw(DoorComboSets[i].bombdoorcombo_r[j],f))
7408 {
7409 new_return(21);
7410 }
7411 960 }
7412
7413
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7414 {
7415
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_putc(DoorComboSets[i].bombdoorcset_r[j],f))
7416 {
7417 new_return(22);
7418 }
7419 960 }
7420
7421 //walkthrough stuff
7422
2/2
✓ Branch 0 taken 1280 times.
✓ Branch 1 taken 320 times.
1600 for(int32_t j=0; j<4; j++)
7423 {
7424
1/2
✓ Branch 0 taken 1280 times.
✗ Branch 1 not taken.
1280 if(!p_iputw(DoorComboSets[i].walkthroughcombo[j],f))
7425 {
7426 new_return(23);
7427 }
7428 1280 }
7429
7430
2/2
✓ Branch 0 taken 1280 times.
✓ Branch 1 taken 320 times.
1600 for(int32_t j=0; j<4; j++)
7431 {
7432
1/2
✓ Branch 0 taken 1280 times.
✗ Branch 1 not taken.
1280 if(!p_putc(DoorComboSets[i].walkthroughcset[j],f))
7433 {
7434 new_return(24);
7435 }
7436 1280 }
7437
7438 //flags
7439
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7440 {
7441
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].flags[j],f))
7442 {
7443 new_return(25);
7444 }
7445 640 }
7446 320 }
7447
7448
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7449 {
7450 9 section_size=writesize;
7451 9 }
7452 18 }
7453
7454
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7455 {
7456 char ebuf[80];
7457 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7458 jwin_alert("Error: writedoorcombosets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7459 }
7460
7461 9 new_return(0);
7462 }
7463
7464 9 int32_t writedmaps(PACKFILE *f, word version, word build, word start_dmap, word max_dmaps)
7465 {
7466 //these are here to bypass compiler warnings about unused arguments
7467 9 version=version;
7468 9 build=build;
7469
7470 9 word dmap_count=count_dmaps();
7471 9 dword section_id=ID_DMAPS;
7472 9 dword section_version=V_DMAPS;
7473 9 dword section_size=0;
7474
7475 //section id
7476
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7477 {
7478 new_return(1);
7479 }
7480
7481 //section version info
7482
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7483 {
7484 new_return(2);
7485 }
7486
7487
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7488 {
7489 new_return(3);
7490 }
7491
7492
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7493 {
7494 18 fake_pack_writing=(writecycle==0);
7495
7496 //section size
7497
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7498 {
7499 new_return(4);
7500 }
7501
7502 18 writesize=0;
7503
7504
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 dmap_count=zc_min(dmap_count, max_dmaps);
7505
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 dmap_count=zc_min(dmap_count, MAXDMAPS-start_dmap);
7506
7507 //finally... section data
7508
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(dmap_count,f))
7509 {
7510 new_return(5);
7511 }
7512
7513
7514
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=start_dmap; i<start_dmap+dmap_count; i++)
7515 {
7516 9216 DMaps[i].validate_subscreens();
7517
7518
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].map,f))
7519 {
7520 new_return(6);
7521 }
7522
7523
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].level,f))
7524 {
7525 new_return(7);
7526 }
7527
7528
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].xoff,f))
7529 {
7530 new_return(8);
7531 }
7532
7533
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].compass,f))
7534 {
7535 new_return(9);
7536 }
7537
7538
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].color,f))
7539 {
7540 new_return(10);
7541 }
7542
7543
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].midi,f))
7544 {
7545 new_return(11);
7546 }
7547
7548
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].cont,f))
7549 {
7550 new_return(12);
7551 }
7552
7553
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].type,f))
7554 {
7555 new_return(13);
7556 }
7557
7558
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t j=0; j<8; j++)
7559 {
7560
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_putc(DMaps[i].grid[j],f))
7561 {
7562 new_return(14);
7563 }
7564 73728 }
7565
7566
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[i].name,sizeof(DMaps[0].name)-1,f))
7567 {
7568 new_return(15);
7569 }
7570
7571
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putwstr(DMaps[i].title,f))
7572 {
7573 new_return(16);
7574 }
7575
7576
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[i].intro,sizeof(DMaps[0].intro)-1,f))
7577 {
7578 new_return(17);
7579 }
7580
7581
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].minimap_tile[0],f))
7582 {
7583 new_return(18);
7584 }
7585
7586
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].minimap_cset[0],f))
7587 {
7588 new_return(19);
7589 }
7590
7591
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].minimap_tile[1],f))
7592 {
7593 new_return(20);
7594 }
7595
7596
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].minimap_cset[1],f))
7597 {
7598 new_return(21);
7599 }
7600
7601
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].largemap_tile[0],f))
7602 {
7603 new_return(22);
7604 }
7605
7606
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].largemap_cset[0],f))
7607 {
7608 new_return(23);
7609 }
7610
7611
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].largemap_tile[1],f))
7612 {
7613 new_return(24);
7614 }
7615
7616
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].largemap_cset[1],f))
7617 {
7618 new_return(25);
7619 }
7620
7621
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[i].tmusic,sizeof(DMaps[0].tmusic)-1,f))
7622 {
7623 new_return(26);
7624 }
7625
7626
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].tmusictrack,f))
7627 {
7628 new_return(25);
7629 }
7630
7631
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].active_subscreen,f))
7632 {
7633 new_return(26);
7634 }
7635
7636
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].passive_subscreen,f))
7637 {
7638 new_return(27);
7639 }
7640
7641 byte disabled[32];
7642 9216 memset(disabled,0,32);
7643
7644
2/2
✓ Branch 0 taken 2359296 times.
✓ Branch 1 taken 9216 times.
2368512 for(int32_t j=0; j<MAXITEMS; j++)
7645 {
7646
1/2
✓ Branch 0 taken 2359296 times.
✗ Branch 1 not taken.
2359296 if(DMaps[i].disableditems[j])
7647 {
7648 disabled[j/8] |= (1 << (j%8));
7649 }
7650 2359296 }
7651
7652
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(disabled,32,f))
7653 {
7654 new_return(28);
7655 }
7656
7657
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].flags,f))
7658 new_return(29);
7659
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].sideview,f))
7660 new_return(30);
7661
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].script,f))
7662 new_return(31);
7663
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
7664
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[i].initD[q],f))
7665 new_return(32);
7666
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
7667
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for ( int32_t w = 0; w < 65; w++ )
7668
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if (!p_putc(DMaps[i].initD_label[q][w],f))
7669 73728 new_return(33);
7670
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].active_sub_script,f))
7671 new_return(34);
7672
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].passive_sub_script,f))
7673 new_return(35);
7674
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7675
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[i].sub_initD[q],f))
7676 new_return(36);
7677
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7678
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for(int32_t w = 0; w < 65; ++w)
7679
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(DMaps[i].sub_initD_label[q][w],f))
7680 73728 new_return(37);
7681
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].onmap_script,f))
7682 new_return(38);
7683
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7684
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[i].onmap_initD[q],f))
7685 new_return(39);
7686
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7687
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for(int32_t w = 0; w < 65; ++w)
7688
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(DMaps[i].onmap_initD_label[q][w],f))
7689 73728 new_return(40);
7690
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].mirrorDMap,f))
7691 new_return(41);
7692
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].tmusic_loop_start, f))
7693 new_return(42);
7694
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].tmusic_loop_end, f))
7695 new_return(43);
7696
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].tmusic_xfade_in, f))
7697 new_return(44);
7698
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].tmusic_xfade_out, f))
7699 new_return(45);
7700
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].overlay_subscreen, f))
7701 new_return(46);
7702
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].intro_string_id, f))
7703 new_return(47);
7704
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (DMaps[i].flags & dmfCUSTOM_GRAVITY)
7705 {
7706 if (!p_iputzf(DMaps[i].dmap_gravity, f))
7707 new_return(48);
7708 if (!p_iputzf(DMaps[i].dmap_terminal_v, f))
7709 new_return(49);
7710 }
7711
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].map_subscreen, f))
7712 new_return(50);
7713
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].floor, f))
7714 new_return(51);
7715 9216 }
7716
7717
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7718 {
7719 9 section_size=writesize;
7720 9 }
7721 18 }
7722
7723
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7724 {
7725 char ebuf[80];
7726 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7727 jwin_alert("Error: writedmaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7728 }
7729
7730 9 new_return(0);
7731 }
7732
7733 9 int32_t writemisccolors(PACKFILE *f, zquestheader *Header)
7734 {
7735 //these are here to bypass compiler warnings about unused arguments
7736 9 Header=Header;
7737
7738 9 dword section_id=ID_COLORS;
7739 9 dword section_version=V_COLORS;
7740 9 dword section_size = 0;
7741
7742 //section id
7743
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7744 {
7745 new_return(1);
7746 }
7747
7748
7749 //section version info
7750
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7751 {
7752 new_return(2);
7753 }
7754
7755
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7756 {
7757 new_return(3);
7758 }
7759
7760
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7761 {
7762 18 fake_pack_writing=(writecycle==0);
7763
7764 //section size
7765
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7766 {
7767 new_return(4);
7768 }
7769
7770 18 writesize=0;
7771
7772
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.text,f))
7773 {
7774 new_return(5);
7775 }
7776
7777
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.caption,f))
7778 {
7779 new_return(6);
7780 }
7781
7782
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.overw_bg,f))
7783 {
7784 new_return(7);
7785 }
7786
7787
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.dngn_bg,f))
7788 {
7789 new_return(8);
7790 }
7791
7792
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.dngn_fg,f))
7793 {
7794 new_return(9);
7795 }
7796
7797
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.cave_fg,f))
7798 {
7799 new_return(10);
7800 }
7801
7802
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bs_dk,f))
7803 {
7804 new_return(11);
7805 }
7806
7807
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bs_goal,f))
7808 {
7809 new_return(12);
7810 }
7811
7812
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.compass_lt,f))
7813 {
7814 new_return(13);
7815 }
7816
7817
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.compass_dk,f))
7818 {
7819 new_return(14);
7820 }
7821
7822
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.subscr_bg,f))
7823 {
7824 new_return(15);
7825 }
7826
7827
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.triframe_color,f))
7828 {
7829 new_return(16);
7830 }
7831
7832
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.hero_dot,f))
7833 {
7834 new_return(17);
7835 }
7836
7837
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bmap_bg,f))
7838 {
7839 new_return(18);
7840 }
7841
7842
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bmap_fg,f))
7843 {
7844 new_return(19);
7845 }
7846
7847
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.triforce_cset,f))
7848 {
7849 new_return(20);
7850 }
7851
7852
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.triframe_cset,f))
7853 {
7854 new_return(21);
7855 }
7856
7857
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.overworld_map_cset,f))
7858 {
7859 new_return(22);
7860 }
7861
7862
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.dungeon_map_cset,f))
7863 {
7864 new_return(23);
7865 }
7866
7867
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.blueframe_cset,f))
7868 {
7869 new_return(24);
7870 }
7871
7872
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.HCpieces_cset,f))
7873 {
7874 new_return(31);
7875 }
7876
7877
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.subscr_shadow,f))
7878 {
7879 new_return(32);
7880 }
7881
7882
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.msgtext,f))
7883 {
7884 new_return(33);
7885 }
7886
7887
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.triforce_tile,f))
7888 {
7889 new_return(34);
7890 }
7891
7892
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.triframe_tile,f))
7893 {
7894 new_return(35);
7895 }
7896
7897
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.overworld_map_tile,f))
7898 {
7899 new_return(36);
7900 }
7901
7902
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.dungeon_map_tile,f))
7903 {
7904 new_return(37);
7905 }
7906
7907
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.blueframe_tile,f))
7908 {
7909 new_return(38);
7910 }
7911
7912
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.HCpieces_tile,f))
7913 {
7914 new_return(39);
7915 }
7916
7917
7918
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7919 {
7920 9 section_size=writesize;
7921 9 }
7922 18 }
7923
7924
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7925 {
7926 char ebuf[80];
7927 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7928 jwin_alert("Error: writemisccolors()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7929 }
7930
7931 9 new_return(0);
7932 }
7933
7934 9 int32_t writegameicons(PACKFILE *f, zquestheader *Header)
7935 {
7936 //these are here to bypass compiler warnings about unused arguments
7937 9 Header=Header;
7938
7939 9 dword section_id=ID_ICONS;
7940 9 dword section_version=V_ICONS;
7941 9 dword section_size = 0;
7942
7943 //section id
7944
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7945 {
7946 new_return(1);
7947 }
7948
7949 //section version info
7950
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7951 {
7952 new_return(2);
7953 }
7954
7955
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7956 {
7957 new_return(3);
7958 }
7959
7960
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7961 {
7962 18 fake_pack_writing=(writecycle==0);
7963
7964 //section size
7965
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7966 {
7967 new_return(4);
7968 }
7969
7970 18 writesize=0;
7971
7972
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
7973 {
7974
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(QMisc.icons[i],f))
7975 {
7976 new_return(5);
7977 }
7978 72 }
7979
7980
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7981 {
7982 9 section_size=writesize;
7983 9 }
7984 18 }
7985
7986
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7987 {
7988 char ebuf[80];
7989 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7990 jwin_alert("Error: writegameicons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7991 }
7992
7993 9 new_return(0);
7994 }
7995
7996 9 int32_t writemisc(PACKFILE *f, zquestheader *Header)
7997 {
7998 //these are here to bypass compiler warnings about unused arguments
7999 9 Header=Header;
8000
8001 9 dword section_id=ID_MISC;
8002 9 dword section_version=V_MISC;
8003 9 word shops=count_shops(&QMisc);
8004 9 word infos=count_infos(&QMisc);
8005 9 word warprings=count_warprings(&QMisc);
8006 9 word triforces=8;
8007 9 dword section_size = 0;
8008
8009 //section id
8010
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8011 {
8012 new_return(1);
8013 }
8014
8015
8016 //section version info
8017
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8018 {
8019 new_return(2);
8020 }
8021
8022
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
8023 {
8024 new_return(3);
8025 }
8026
8027
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8028 {
8029 18 fake_pack_writing=(writecycle==0);
8030
8031 //section size
8032
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8033 {
8034 new_return(4);
8035 }
8036
8037 18 writesize=0;
8038
8039 //shops
8040
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(shops,f))
8041 {
8042 new_return(5);
8043 }
8044
8045
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<shops; i++)
8046 {
8047
1/2
✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
160 if(!pfwrite(QMisc.shop[i].name,sizeof(QMisc.shop[i].name)-1,f))
8048 {
8049 new_return(6);
8050 }
8051
8052
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8053 {
8054
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_putc(QMisc.shop[i].item[j],f))
8055 {
8056 new_return(7);
8057 }
8058 480 }
8059
8060
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8061 {
8062
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.shop[i].price[j],f))
8063 {
8064 new_return(8);
8065 }
8066 480 }
8067
8068
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8069 {
8070
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_putc(QMisc.shop[i].hasitem[j],f))
8071 {
8072 new_return(9);
8073 }
8074 480 }
8075 160 }
8076
8077 //infos
8078
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(infos,f))
8079 {
8080 new_return(10);
8081 }
8082
8083
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<infos; i++)
8084 {
8085
1/2
✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
160 if(!pfwrite(QMisc.info[i].name,sizeof(QMisc.info[i].name)-1,f))
8086 {
8087 new_return(11);
8088 }
8089
8090
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8091 {
8092
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.info[i].str[j],f))
8093 {
8094 new_return(12);
8095 }
8096 480 }
8097
8098
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8099 {
8100
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.info[i].price[j],f))
8101 {
8102 new_return(13);
8103 }
8104 480 }
8105 160 }
8106
8107 //warp rings
8108
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(warprings,f))
8109 {
8110 new_return(14);
8111 }
8112
8113
2/2
✓ Branch 0 taken 208 times.
✓ Branch 1 taken 18 times.
226 for(int32_t i=0; i<warprings; i++)
8114 {
8115
2/2
✓ Branch 0 taken 1872 times.
✓ Branch 1 taken 208 times.
2080 for(int32_t j=0; j<9; j++)
8116 {
8117
1/2
✓ Branch 0 taken 1872 times.
✗ Branch 1 not taken.
1872 if(!p_iputw(QMisc.warp[i].dmap[j],f))
8118 {
8119 new_return(15);
8120 }
8121 1872 }
8122
8123
2/2
✓ Branch 0 taken 1872 times.
✓ Branch 1 taken 208 times.
2080 for(int32_t j=0; j<9; j++)
8124 {
8125
1/2
✓ Branch 0 taken 1872 times.
✗ Branch 1 not taken.
1872 if(!p_putc(QMisc.warp[i].scr[j],f))
8126 {
8127 new_return(16);
8128 }
8129 1872 }
8130
8131
1/2
✓ Branch 0 taken 208 times.
✗ Branch 1 not taken.
208 if(!p_putc(QMisc.warp[i].size,f))
8132 {
8133 new_return(17);
8134 }
8135 208 }
8136
8137 //triforce pieces
8138
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 18 times.
162 for(int32_t i=0; i<triforces; i++)
8139 {
8140
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(!p_putc(QMisc.triforce[i],f))
8141 {
8142 new_return(18);
8143 }
8144 144 }
8145
8146 //end string
8147
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(QMisc.endstring,f))
8148 {
8149 new_return(19);
8150 }
8151
8152 //V_MISC >= 8
8153
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<shops; i++)
8154 {
8155
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8156 {
8157
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.shop[i].str[j],f))
8158 {
8159 new_return(20);
8160 }
8161 480 }
8162 160 }
8163 //V_MISC >= 9
8164
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for ( int32_t q = 0; q < 32; q++ )
8165 {
8166
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_iputl(QMisc.questmisc[q],f))
8167 new_return(21);
8168 576 }
8169
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for ( int32_t q = 0; q < 32; q++ )
8170 {
8171
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 576 times.
74304 for ( int32_t j = 0; j < 128; j++ )
8172
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_putc(0,f))
8173 new_return(22);
8174 576 }
8175 //V_MISC >= 11
8176
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.zscript_last_compiled_version,f))
8177 new_return(23);
8178
8179 //V_MISC >= 12
8180
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t q = 0; q < sprMAX; ++q)
8181 {
8182
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(QMisc.sprites[q],f))
8183 new_return(24);
8184 4608 }
8185
8186 //V_MISC >= 13
8187
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 18 times.
1170 for(size_t q = 0; q < 64; ++q)
8188 {
8189 1152 bottletype* bt = &(QMisc.bottle_types[q]);
8190
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!pfwrite(bt->name, 32, f))
8191 new_return(25);
8192
2/2
✓ Branch 0 taken 3456 times.
✓ Branch 1 taken 1152 times.
4608 for(size_t j = 0; j < 3; ++j)
8193 {
8194
1/2
✓ Branch 0 taken 3456 times.
✗ Branch 1 not taken.
3456 if (!p_putc(bt->counter[j], f))
8195 new_return(25);
8196
1/2
✓ Branch 0 taken 3456 times.
✗ Branch 1 not taken.
3456 if (!p_iputw(bt->amount[j], f))
8197 new_return(25);
8198 3456 }
8199
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!p_putc(bt->flags, f))
8200 new_return(25);
8201
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!p_putc(bt->next_type, f))
8202 new_return(25);
8203 1152 }
8204
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(size_t q = 0; q < 256; ++q)
8205 {
8206 4608 bottleshoptype* bst = &(QMisc.bottle_shop_types[q]);
8207
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if (!pfwrite(bst->name, 32, f))
8208 new_return(26);
8209
2/2
✓ Branch 0 taken 13824 times.
✓ Branch 1 taken 4608 times.
18432 for(size_t j = 0; j < 3; ++j)
8210 {
8211
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_putc(bst->fill[j], f))
8212 new_return(26);
8213
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_iputw(bst->comb[j], f))
8214 new_return(26);
8215
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_putc(bst->cset[j], f))
8216 new_return(26);
8217
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_iputw(bst->price[j], f))
8218 new_return(26);
8219
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13824 times.
13824 if (!p_iputw(bst->str[j], f))
8220 new_return(26);
8221 13824 }
8222 4608 }
8223
8224 //V_MISC >= 14
8225
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t q = 0; q < sfxMAX; ++q)
8226 {
8227
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(QMisc.miscsfx[q],f))
8228 new_return(27);
8229 4608 }
8230
8231
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8232 {
8233 9 section_size=writesize;
8234 9 }
8235 18 }
8236
8237
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8238 {
8239 char ebuf[80];
8240 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8241 jwin_alert("Error: writemisc()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8242 }
8243
8244 9 new_return(0);
8245 }
8246
8247 9 int32_t writeitems(PACKFILE *f, zquestheader *Header)
8248 {
8249 //these are here to bypass compiler warnings about unused arguments
8250 9 Header=Header;
8251
8252 9 dword section_id=ID_ITEMS;
8253 9 dword section_version=V_ITEMS;
8254 // dword section_size=0;
8255 9 dword section_size = 0;
8256
8257 //section id
8258
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8259 {
8260 new_return(1);
8261 }
8262
8263 //section version info
8264
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8265 {
8266 new_return(2);
8267 }
8268
8269
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
8270 {
8271 new_return(3);
8272 }
8273
8274
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8275 {
8276 18 fake_pack_writing=(writecycle==0);
8277
8278 //section size
8279
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8280 {
8281 new_return(4);
8282 }
8283
8284 18 writesize=0;
8285
8286 //finally... section data
8287
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(MAXITEMS,f))
8288 {
8289 new_return(5);
8290 }
8291
8292
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXITEMS; i++)
8293 {
8294
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!pfwrite(item_string[i], 64, f))
8295 {
8296 new_return(5);
8297 }
8298 4608 }
8299
8300
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXITEMS; i++)
8301 {
8302
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tile,f))
8303 {
8304 new_return(6);
8305 }
8306
8307
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].misc_flags,f))
8308 {
8309 new_return(7);
8310 }
8311
8312
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].csets,f))
8313 {
8314 new_return(8);
8315 }
8316
8317
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].frames,f))
8318 {
8319 new_return(9);
8320 }
8321
8322
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].speed,f))
8323 {
8324 new_return(10);
8325 }
8326
8327
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].delay,f))
8328 {
8329 new_return(11);
8330 }
8331
8332
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].ltm,f))
8333 {
8334 new_return(12);
8335 }
8336
8337
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].type,f))
8338 {
8339 new_return(13);
8340 }
8341
8342
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].level,f))
8343 {
8344 new_return(14);
8345 }
8346
8347
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].power,f))
8348 {
8349 new_return(14);
8350 }
8351
8352
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].flags,f))
8353 {
8354 new_return(15);
8355 }
8356
8357
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].script,f))
8358 {
8359 new_return(16);
8360 }
8361
8362
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].count,f))
8363 {
8364 new_return(17);
8365 }
8366
8367
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].amount,f))
8368 {
8369 new_return(18);
8370 }
8371
8372
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].collect_script,f))
8373 {
8374 new_return(19);
8375 }
8376
8377
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].setmax,f))
8378 {
8379 new_return(21);
8380 }
8381
8382
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].max,f))
8383 {
8384 new_return(22);
8385 }
8386
8387
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].playsound,f))
8388 {
8389 new_return(23);
8390 }
8391
8392
2/2
✓ Branch 0 taken 36864 times.
✓ Branch 1 taken 4608 times.
41472 for(int32_t j=0; j<8; j++)
8393 {
8394
1/2
✓ Branch 0 taken 36864 times.
✗ Branch 1 not taken.
36864 if(!p_iputl(itemsbuf[i].initiald[j],f))
8395 {
8396 new_return(24);
8397 }
8398 36864 }
8399
8400
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(int32_t j=0; j<2; j++)
8401 {
8402
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8403 {
8404 new_return(25);
8405 }
8406 9216 }
8407
8408
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn,f))
8409 {
8410 new_return(26);
8411 }
8412
8413
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn2,f))
8414 {
8415 new_return(27);
8416 }
8417
8418
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(!p_putc(itemsbuf[i].wpn3,f))
8419 {
8420 new_return(28);
8421 }
8422
8423
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn4,f))
8424 {
8425 new_return(29);
8426 }
8427
8428
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn5,f))
8429 {
8430 new_return(30);
8431 }
8432
8433
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn6,f))
8434 {
8435 new_return(31);
8436 }
8437
8438
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(!p_putc(itemsbuf[i].wpn7,f))
8439 {
8440 new_return(32);
8441 }
8442
8443
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn8,f))
8444 {
8445 new_return(33);
8446 }
8447
8448
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn9,f))
8449 {
8450 new_return(34);
8451 }
8452
8453
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn10,f))
8454 {
8455 new_return(35);
8456 }
8457
8458
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(!p_putc(itemsbuf[i].pickup_hearts,f))
8459 {
8460 new_return(36);
8461 }
8462
8463
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc1,f))
8464 {
8465 new_return(37);
8466 }
8467
8468
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc2,f))
8469 {
8470 new_return(38);
8471 }
8472
8473
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8474 {
8475
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(itemsbuf[i].cost_amount[q],f))
8476 {
8477 new_return(39);
8478 }
8479 9216 }
8480
8481
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc3,f))
8482 {
8483 new_return(40);
8484 }
8485
8486
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc4,f))
8487 {
8488 new_return(41);
8489 }
8490
8491
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc5,f))
8492 {
8493 new_return(42);
8494 }
8495
8496
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc6,f))
8497 {
8498 new_return(43);
8499 }
8500
8501
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc7,f))
8502 {
8503 new_return(44);
8504 }
8505
8506
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc8,f))
8507 {
8508 new_return(45);
8509 }
8510
8511
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc9,f))
8512 {
8513 new_return(46);
8514 }
8515
8516
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc10,f))
8517 {
8518 new_return(47);
8519 }
8520
8521
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].usesound,f))
8522 {
8523 new_return(48);
8524 }
8525
8526
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].usesound2,f))
8527 {
8528 new_return(48);
8529 }
8530
8531 //New itemdata vars -Z
8532 //! version 27
8533
8534
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weaprange,f))
8535 {
8536 new_return(51);
8537 }
8538
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weapduration,f))
8539 {
8540 new_return(52);
8541 }
8542
2/2
✓ Branch 0 taken 46080 times.
✓ Branch 1 taken 4608 times.
50688 for ( int32_t q = 0; q < ITEM_MOVEMENT_PATTERNS; q++ ) {
8543
1/2
✓ Branch 0 taken 46080 times.
✗ Branch 1 not taken.
46080 if(!p_iputl(itemsbuf[i].weap_pattern[q],f))
8544 {
8545 new_return(53);
8546 }
8547 46080 }
8548 //version 28
8549
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].duplicates,f))
8550 {
8551 new_return(54);
8552 }
8553
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for ( int32_t q = 0; q < 2; q++ )
8554 {
8555
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8556 {
8557 new_return(56);
8558 }
8559 9216 }
8560
8561
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].drawlayer,f))
8562 {
8563 new_return(57);
8564 }
8565
8566
8567
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hxofs,f))
8568 {
8569 new_return(58);
8570 }
8571
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hyofs,f))
8572 {
8573 new_return(59);
8574 }
8575
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hxsz,f))
8576 {
8577 new_return(60);
8578 }
8579
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hysz,f))
8580 {
8581 new_return(61);
8582 }
8583
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hzsz,f))
8584 {
8585 new_return(62);
8586 }
8587
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].xofs,f))
8588 {
8589 new_return(63);
8590 }
8591
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].yofs,f))
8592 {
8593 new_return(64);
8594 }
8595
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].wpnsprite,f))
8596 {
8597 new_return(73);
8598 }
8599
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8600 {
8601
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(itemsbuf[i].magiccosttimer[q],f))
8602 {
8603 new_return(74);
8604 }
8605 9216 }
8606
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].overrideFLAGS,f))
8607 {
8608 new_return(75);
8609 }
8610
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tilew,f))
8611 {
8612 new_return(76);
8613 }
8614
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tileh,f))
8615 {
8616 new_return(77);
8617 }
8618
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].pickup,f))
8619 {
8620 new_return(81);
8621 }
8622
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].pstring,f))
8623 {
8624 new_return(82);
8625 }
8626
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].pickup_string_flags,f))
8627 {
8628 new_return(83);
8629 }
8630
8631
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8632 {
8633
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(itemsbuf[i].cost_counter[q],f))
8634 {
8635 new_return(84);
8636 }
8637 9216 }
8638
8639 //InitD[] labels
8640
2/2
✓ Branch 0 taken 36864 times.
✓ Branch 1 taken 4608 times.
41472 for ( int32_t q = 0; q < 8; q++ )
8641 {
8642
2/2
✓ Branch 0 taken 2396160 times.
✓ Branch 1 taken 36864 times.
2433024 for ( int32_t w = 0; w < 65; w++ )
8643 {
8644
1/2
✓ Branch 0 taken 2396160 times.
✗ Branch 1 not taken.
2396160 if(!p_putc(itemsbuf[i].initD_label[q][w],f))
8645 {
8646 new_return(85);
8647 }
8648 2396160 }
8649
2/2
✓ Branch 0 taken 2396160 times.
✓ Branch 1 taken 36864 times.
2433024 for ( int32_t w = 0; w < 65; w++ )
8650 {
8651
1/2
✓ Branch 0 taken 2396160 times.
✗ Branch 1 not taken.
2396160 if(!p_putc(itemsbuf[i].sprite_initD_label[q][w],f))
8652 {
8653 new_return(87);
8654 }
8655 2396160 }
8656
1/2
✓ Branch 0 taken 36864 times.
✗ Branch 1 not taken.
36864 if(!p_iputl(itemsbuf[i].sprite_initiald[q],f))
8657 {
8658 new_return(88);
8659 }
8660 36864 }
8661
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for ( int32_t q = 0; q < 2; q++ )
8662 {
8663
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8664 {
8665 new_return(89);
8666 }
8667
8668 9216 }
8669
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].sprite_script,f))
8670 {
8671 new_return(90);
8672 }
8673
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].pickupflag,f))
8674 {
8675 new_return(91);
8676 }
8677
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 std::string dispname(itemsbuf[i].display_name);
8678
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4608 times.
4608 if(!p_putcstr(dispname,f))
8679 new_return(92);
8680
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if(!p_iputw(itemsbuf[i].pickup_litems, f))
8681 new_return(95);
8682
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if(!p_iputw(itemsbuf[i].pickup_litem_level, f))
8683 new_return(96);
8684
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4608 times.
4608 if (!p_iputl(itemsbuf[i].moveflags, f))
8685 new_return(97);
8686
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4608 times.
4608 if(auto ret = write_weap_data(itemsbuf[i].weap_data, f))
8687 return ret;
8688
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if (!p_iputl(itemsbuf[i].cooldown, f))
8689 new_return(98);
8690
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
4608 }
8691
8692
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8693 {
8694 9 section_size=writesize;
8695 9 }
8696 18 }
8697
8698
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8699 {
8700 char ebuf[80];
8701 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8702 jwin_alert("Error: writeitems()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8703 }
8704
8705 9 new_return(0);
8706 9 }
8707
8708 9 int32_t writeweapons(PACKFILE *f, zquestheader *Header)
8709 {
8710 //these are here to bypass compiler warnings about unused arguments
8711 9 Header=Header;
8712
8713 9 dword section_id=ID_WEAPONS;
8714 9 dword section_version=V_WEAPONS;
8715 9 dword section_size = 0;
8716
8717 //section id
8718
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8719 {
8720 new_return(1);
8721 }
8722
8723 //section version info
8724
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8725 {
8726 new_return(2);
8727 }
8728
8729
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
8730 {
8731 new_return(3);
8732 }
8733
8734
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8735 {
8736 18 fake_pack_writing=(writecycle==0);
8737
8738 //section size
8739
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8740 {
8741 new_return(4);
8742 }
8743
8744 18 writesize=0;
8745
8746 //finally... section data
8747
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(MAXWPNS,f))
8748 {
8749 new_return(5);
8750 }
8751
8752
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXWPNS; i++)
8753 {
8754
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!pfwrite((char *)weapon_string[i], 64, f))
8755 {
8756 new_return(5);
8757 }
8758 4608 }
8759
8760
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXWPNS; i++)
8761 {
8762
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].misc,f))
8763 {
8764 new_return(7);
8765 }
8766
8767
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].csets,f))
8768 {
8769 new_return(8);
8770 }
8771
8772
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].frames,f))
8773 {
8774 new_return(9);
8775 }
8776
8777
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].speed,f))
8778 {
8779 new_return(10);
8780 }
8781
8782
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].type,f))
8783 {
8784 new_return(11);
8785 }
8786
8787
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(wpnsbuf[i].script,f))
8788 {
8789 new_return(12);
8790 }
8791
8792
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(wpnsbuf[i].tile,f))
8793 {
8794 new_return(12);
8795 }
8796 4608 }
8797
8798
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8799 {
8800 9 section_size=writesize;
8801 9 }
8802 18 }
8803
8804
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8805 {
8806 char ebuf[80];
8807 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8808 jwin_alert("Error: writeweapons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8809 }
8810
8811 9 new_return(0);
8812 }
8813
8814 12784 int32_t writemapscreen(PACKFILE *f, int32_t i, int32_t j)
8815 {
8816
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12784 times.
12784 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
8817 return qe_invalid;
8818
8819 12784 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
8820 12784 bool is_0x80_screen = j >= 0x80;
8821
8822
1/2
✓ Branch 0 taken 12784 times.
✗ Branch 1 not taken.
12784 if(!p_putc(screen.valid,f))
8823 return qe_invalid;
8824
2/2
✓ Branch 0 taken 8380 times.
✓ Branch 1 taken 4404 times.
12784 if(!(screen.valid & mVALID))
8825 4404 return qe_OK;
8826 //Calculate what needs writing
8827 8380 uint32_t scr_has_flags = 0;
8828
4/8
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8378 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
8380 if(screen.guytile || screen.guy || screen.roomflags || screen.str
8829
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 || screen.room || screen.catchall)
8830 8380 scr_has_flags |= SCRHAS_ROOMDATA;
8831
7/8
✓ Branch 0 taken 7946 times.
✓ Branch 1 taken 434 times.
✓ Branch 2 taken 192 times.
✓ Branch 3 taken 7754 times.
✓ Branch 4 taken 180 times.
✓ Branch 5 taken 12 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 180 times.
8380 if(screen.hasitem || (is_0x80_screen && (screen.itemx||screen.itemy)))
8832 446 scr_has_flags |= SCRHAS_ITEM;
8833
3/4
✓ Branch 0 taken 8352 times.
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8352 times.
8380 if((screen.warpreturnc&0x00FF) || screen.tilewarpoverlayflags)
8834 28 scr_has_flags |= SCRHAS_TWARP;
8835
2/2
✓ Branch 0 taken 8176 times.
✓ Branch 1 taken 32882 times.
41058 else for(auto q = 0; q < 4; ++q)
8836 {
8837
1/2
✓ Branch 0 taken 32706 times.
✗ Branch 1 not taken.
65588 if(screen.tilewarptype[q]
8838
2/2
✓ Branch 0 taken 32708 times.
✓ Branch 1 taken 174 times.
32882 || screen.tilewarpdmap[q]
8839
2/2
✓ Branch 0 taken 32706 times.
✓ Branch 1 taken 2 times.
32708 || screen.tilewarpscr[q])
8840 {
8841 176 scr_has_flags |= SCRHAS_TWARP;
8842 176 break;
8843 }
8844 32706 }
8845
3/4
✓ Branch 0 taken 8376 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8344 times.
8380 if((screen.warpreturnc&0xFF00) || screen.sidewarpindex
8846
2/2
✓ Branch 0 taken 8344 times.
✓ Branch 1 taken 32 times.
8376 || screen.sidewarpoverlayflags)
8847 36 scr_has_flags |= SCRHAS_SWARP;
8848
2/2
✓ Branch 0 taken 4074 times.
✓ Branch 1 taken 20568 times.
24642 else for(auto q = 0; q < 4; ++q)
8849 {
8850
2/2
✓ Branch 0 taken 16298 times.
✓ Branch 1 taken 12 times.
36878 if(screen.sidewarptype[q] != wtSCROLL
8851
2/2
✓ Branch 0 taken 16436 times.
✓ Branch 1 taken 4132 times.
20568 || screen.sidewarpdmap[q]
8852
2/2
✓ Branch 0 taken 16310 times.
✓ Branch 1 taken 126 times.
16436 || screen.sidewarpscr[q])
8853 {
8854 4270 scr_has_flags |= SCRHAS_SWARP;
8855 4270 break;
8856 }
8857 16298 }
8858
3/4
✓ Branch 0 taken 8336 times.
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8336 times.
8380 if(screen.warparrivalx || screen.warparrivaly)
8859 44 scr_has_flags |= SCRHAS_WARPRET;
8860
2/2
✓ Branch 0 taken 7552 times.
✓ Branch 1 taken 30992 times.
38544 else for(auto q = 0; q < 4; ++q)
8861 {
8862
4/4
✓ Branch 0 taken 30210 times.
✓ Branch 1 taken 782 times.
✓ Branch 2 taken 30208 times.
✓ Branch 3 taken 2 times.
30992 if(screen.warpreturnx[q] || screen.warpreturny[q])
8863 {
8864 784 scr_has_flags |= SCRHAS_WARPRET;
8865 784 break;
8866 }
8867 30208 }
8868
8869
2/4
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8380 times.
8380 if(screen.hidelayers || screen.hidescriptlayers)
8870 scr_has_flags |= SCRHAS_LAYERS;
8871
2/2
✓ Branch 0 taken 7414 times.
✓ Branch 1 taken 45498 times.
52912 else for(auto q = 0; q < 6; ++q)
8872 {
8873
4/4
✓ Branch 0 taken 44552 times.
✓ Branch 1 taken 946 times.
✓ Branch 2 taken 44532 times.
✓ Branch 3 taken 20 times.
45498 if(screen.layermap[q] || screen.layerscreen[q]
8874
1/2
✓ Branch 0 taken 44552 times.
✗ Branch 1 not taken.
44552 || screen.layeropacity[q]!=255)
8875 {
8876 966 scr_has_flags |= SCRHAS_LAYERS;
8877 966 break;
8878 }
8879 44532 }
8880
8881
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 8370 times.
8380 if(screen.exitdir)
8882 10 scr_has_flags |= SCRHAS_MAZE;
8883
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8370 times.
8370 else if(screen.maze_transition_wipe)
8884 scr_has_flags |= SCRHAS_MAZE;
8885
2/2
✓ Branch 0 taken 8370 times.
✓ Branch 1 taken 33480 times.
41850 else for(auto q = 0; q < 4; ++q)
8886 {
8887
1/2
✓ Branch 0 taken 33480 times.
✗ Branch 1 not taken.
33480 if(screen.path[q])
8888 {
8889 scr_has_flags |= SCRHAS_MAZE;
8890 break;
8891 }
8892 33480 }
8893
8894
4/4
✓ Branch 0 taken 8146 times.
✓ Branch 1 taken 234 times.
✓ Branch 2 taken 322 times.
✓ Branch 3 taken 5412 times.
14114 if(screen.door_combo_set || screen.stairx
8895
3/4
✓ Branch 0 taken 8118 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 8118 times.
✗ Branch 3 not taken.
8146 || screen.stairy || screen.undercombo
8896
2/2
✓ Branch 0 taken 5734 times.
✓ Branch 1 taken 2384 times.
8118 || screen.undercset)
8897 2968 scr_has_flags |= SCRHAS_D_S_U;
8898
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 6012 times.
6212 else for(auto q = 0; q < 4; ++q)
8899 {
8900
2/2
✓ Branch 0 taken 800 times.
✓ Branch 1 taken 5212 times.
6012 if(screen.door[q] != dNONE)
8901 {
8902 5212 scr_has_flags |= SCRHAS_D_S_U;
8903 5212 break;
8904 }
8905 800 }
8906
8907
2/2
✓ Branch 0 taken 8076 times.
✓ Branch 1 taken 304 times.
15600 if(screen.flags || screen.flags2
8908
4/4
✓ Branch 0 taken 7830 times.
✓ Branch 1 taken 246 times.
✓ Branch 2 taken 7698 times.
✓ Branch 3 taken 132 times.
8076 || screen.flags3 || screen.flags4
8909
4/4
✓ Branch 0 taken 7684 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 7662 times.
✓ Branch 3 taken 22 times.
7698 || screen.flags5 || screen.flags6
8910
4/4
✓ Branch 0 taken 7448 times.
✓ Branch 1 taken 214 times.
✓ Branch 2 taken 7220 times.
✓ Branch 3 taken 228 times.
7662 || screen.flags7 || screen.flags8
8911
2/4
✓ Branch 0 taken 7220 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7220 times.
✗ Branch 3 not taken.
7220 || screen.flags9 || screen.flags10
8912
1/2
✓ Branch 0 taken 7220 times.
✗ Branch 1 not taken.
7220 || screen.flags11)
8913 8380 scr_has_flags |= SCRHAS_FLAGS;
8914
8915
2/2
✓ Branch 0 taken 58 times.
✓ Branch 1 taken 8322 times.
8380 if(screen.pattern)
8916 58 scr_has_flags |= SCRHAS_ENEMY;
8917
2/2
✓ Branch 0 taken 7308 times.
✓ Branch 1 taken 74100 times.
81408 else for(auto q = 0; q < 10; ++q)
8918 {
8919
2/2
✓ Branch 0 taken 73086 times.
✓ Branch 1 taken 1014 times.
74100 if(screen.enemy[q])
8920 {
8921 1014 scr_has_flags |= SCRHAS_ENEMY;
8922 1014 break;
8923 }
8924 73086 }
8925
8926
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
8380 if(screen.noreset != mDEF_NORESET || screen.nocarry != mDEF_NOCARRYOVER
8927 || screen.nextmap || screen.nextscr || screen.exstate_reset || screen.exstate_carry)
8928 8380 scr_has_flags |= SCRHAS_CARRY;
8929
8930
3/4
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8358 times.
8380 if(screen.script || screen.preloadscript)
8931 22 scr_has_flags |= SCRHAS_SCRIPT;
8932
2/2
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 66864 times.
75222 else for(auto q = 0; q < 8; ++q)
8933 {
8934
1/2
✓ Branch 0 taken 66864 times.
✗ Branch 1 not taken.
66864 if(screen.screeninitd[q])
8935 {
8936 scr_has_flags |= SCRHAS_SCRIPT;
8937 break;
8938 }
8939 66864 }
8940
8941
2/2
✓ Branch 0 taken 5304 times.
✓ Branch 1 taken 683992 times.
689296 for(auto q = 0; q < 128; ++q)
8942 {
8943
1/2
✓ Branch 0 taken 680916 times.
✗ Branch 1 not taken.
1364908 if(screen.secretcombo[q]
8944
2/2
✓ Branch 0 taken 680922 times.
✓ Branch 1 taken 3070 times.
683992 || screen.secretcset[q]
8945
2/2
✓ Branch 0 taken 680916 times.
✓ Branch 1 taken 6 times.
680922 || screen.secretflag[q])
8946 {
8947 3076 scr_has_flags |= SCRHAS_SECRETS;
8948 3076 break;
8949 }
8950 680916 }
8951
8952
2/2
✓ Branch 0 taken 3020 times.
✓ Branch 1 taken 573892 times.
576912 for(auto q = 0; q < 176; ++q)
8953 {
8954
4/4
✓ Branch 0 taken 568780 times.
✓ Branch 1 taken 5112 times.
✓ Branch 2 taken 568532 times.
✓ Branch 3 taken 12 times.
573892 if(screen.data[q] || screen.cset[q]
8955
2/2
✓ Branch 0 taken 568544 times.
✓ Branch 1 taken 236 times.
568780 || screen.sflag[q])
8956 {
8957 5360 scr_has_flags |= SCRHAS_COMBOFLAG;
8958 5360 break;
8959 }
8960 568532 }
8961
8962
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 2236 times.
8380 if(screen.color || screen.csensitive != 1
8963
3/4
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6110 times.
✓ Branch 3 taken 34 times.
6144 || screen.oceansfx || screen.bosssfx
8964
2/4
✓ Branch 0 taken 6110 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6110 times.
6110 || screen.secretsfx || screen.holdupsfx
8965 || screen.timedwarptics || screen.screen_midi != -1
8966 || screen.lens_layer || screen.lens_show || screen.lens_hide)
8967 8380 scr_has_flags |= SCRHAS_MISC;
8968
8969
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(scr_has_flags,f))
8970 return qe_invalid;
8971
8972 //Write stuff
8973
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_ROOMDATA)
8974 {
8975
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.guy,f))
8976 return qe_invalid;
8977
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.guytile,f))
8978 return qe_invalid;
8979
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.guycs,f))
8980 return qe_invalid;
8981
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.roomflags,f))
8982 return qe_invalid;
8983
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.str,f))
8984 return qe_invalid;
8985
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.room,f))
8986 return qe_invalid;
8987
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.catchall,f))
8988 return qe_invalid;
8989 8380 }
8990
2/2
✓ Branch 0 taken 7934 times.
✓ Branch 1 taken 446 times.
8380 if(scr_has_flags & SCRHAS_ITEM)
8991 {
8992
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.item,f))
8993 return qe_invalid;
8994
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.hasitem,f))
8995 return qe_invalid;
8996
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.itemx,f))
8997 return qe_invalid;
8998
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.itemy,f))
8999 return qe_invalid;
9000 446 }
9001
2/2
✓ Branch 0 taken 4006 times.
✓ Branch 1 taken 4374 times.
8380 if(scr_has_flags & (SCRHAS_SWARP|SCRHAS_TWARP))
9002 {
9003
1/2
✓ Branch 0 taken 4374 times.
✗ Branch 1 not taken.
4374 if(!p_iputw(screen.warpreturnc,f))
9004 return qe_invalid;
9005 4374 }
9006
2/2
✓ Branch 0 taken 8176 times.
✓ Branch 1 taken 204 times.
8380 if(scr_has_flags & SCRHAS_TWARP)
9007 {
9008
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9009 {
9010
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_putc(screen.tilewarptype[k],f))
9011 return qe_invalid;
9012 816 }
9013
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9014 {
9015
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_iputw(screen.tilewarpdmap[k],f))
9016 return qe_invalid;
9017 816 }
9018
9019
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9020 {
9021
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_putc(screen.tilewarpscr[k],f))
9022 return qe_invalid;
9023 816 }
9024
9025
1/2
✓ Branch 0 taken 204 times.
✗ Branch 1 not taken.
204 if(!p_putc(screen.tilewarpoverlayflags,f))
9026 return qe_invalid;
9027 204 }
9028
2/2
✓ Branch 0 taken 4074 times.
✓ Branch 1 taken 4306 times.
8380 if(scr_has_flags & SCRHAS_SWARP)
9029 {
9030
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9031 {
9032
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_putc(screen.sidewarptype[k],f))
9033 return qe_invalid;
9034 17224 }
9035
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9036 {
9037
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_iputw(screen.sidewarpdmap[k],f))
9038 return qe_invalid;
9039 17224 }
9040
9041
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9042 {
9043
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_putc(screen.sidewarpscr[k],f))
9044 return qe_invalid;
9045 17224 }
9046
9047
1/2
✓ Branch 0 taken 4306 times.
✗ Branch 1 not taken.
4306 if(!p_putc(screen.sidewarpoverlayflags,f))
9048 return qe_invalid;
9049
1/2
✓ Branch 0 taken 4306 times.
✗ Branch 1 not taken.
4306 if(!p_putc(screen.sidewarpindex,f))
9050 return qe_invalid;
9051 4306 }
9052
2/2
✓ Branch 0 taken 7552 times.
✓ Branch 1 taken 828 times.
8380 if(scr_has_flags & SCRHAS_WARPRET)
9053 {
9054
2/2
✓ Branch 0 taken 3312 times.
✓ Branch 1 taken 828 times.
4140 for(int32_t k=0; k<4; k++)
9055 {
9056
1/2
✓ Branch 0 taken 3312 times.
✗ Branch 1 not taken.
3312 if(!p_putc(screen.warpreturnx[k],f))
9057 return qe_invalid;
9058 3312 }
9059
2/2
✓ Branch 0 taken 3312 times.
✓ Branch 1 taken 828 times.
4140 for(int32_t k=0; k<4; k++)
9060 {
9061
1/2
✓ Branch 0 taken 3312 times.
✗ Branch 1 not taken.
3312 if(!p_putc(screen.warpreturny[k],f))
9062 return qe_invalid;
9063 3312 }
9064
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(screen.warparrivalx,f))
9065 return qe_invalid;
9066
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(screen.warparrivaly,f))
9067 return qe_invalid;
9068 828 }
9069
2/2
✓ Branch 0 taken 7414 times.
✓ Branch 1 taken 966 times.
8380 if(scr_has_flags & SCRHAS_LAYERS)
9070 {
9071
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9072 {
9073
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layermap[k],f))
9074 return qe_invalid;
9075 5796 }
9076
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9077 {
9078
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layerscreen[k],f))
9079 return qe_invalid;
9080 5796 }
9081
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9082 {
9083
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layeropacity[k],f))
9084 return qe_invalid;
9085 5796 }
9086
1/2
✓ Branch 0 taken 966 times.
✗ Branch 1 not taken.
966 if(!p_putc(screen.hidelayers,f))
9087 return qe_invalid;
9088
1/2
✓ Branch 0 taken 966 times.
✗ Branch 1 not taken.
966 if(!p_putc(screen.hidescriptlayers,f))
9089 return qe_invalid;
9090 966 }
9091
2/2
✓ Branch 0 taken 8370 times.
✓ Branch 1 taken 10 times.
8380 if(scr_has_flags & SCRHAS_MAZE)
9092 {
9093
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 10 times.
50 for(int32_t k=0; k<4; k++)
9094 {
9095
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if(!p_putc(screen.path[k],f))
9096 return qe_invalid;
9097 40 }
9098
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(screen.exitdir,f))
9099 return qe_invalid;
9100
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(screen.maze_transition_wipe,f))
9101 return qe_invalid;
9102 10 }
9103
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 8180 times.
8380 if(scr_has_flags & SCRHAS_D_S_U)
9104 {
9105
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_iputw(screen.door_combo_set,f))
9106 return qe_invalid;
9107
2/2
✓ Branch 0 taken 32720 times.
✓ Branch 1 taken 8180 times.
40900 for(int32_t k=0; k<4; k++)
9108 {
9109
1/2
✓ Branch 0 taken 32720 times.
✗ Branch 1 not taken.
32720 if(!p_putc(screen.door[k],f))
9110 return qe_invalid;
9111 32720 }
9112
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.stairx,f))
9113 return qe_invalid;
9114
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.stairy,f))
9115 return qe_invalid;
9116
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_iputw(screen.undercombo,f))
9117 return qe_invalid;
9118
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.undercset,f))
9119 return qe_invalid;
9120 8180 }
9121
2/2
✓ Branch 0 taken 7086 times.
✓ Branch 1 taken 1294 times.
8380 if(scr_has_flags & SCRHAS_FLAGS)
9122 {
9123
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags,f))
9124 return qe_invalid;
9125
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags2,f))
9126 return qe_invalid;
9127
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags3,f))
9128 return qe_invalid;
9129
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags4,f))
9130 return qe_invalid;
9131
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags5,f))
9132 return qe_invalid;
9133
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags6,f))
9134 return qe_invalid;
9135
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags7,f))
9136 return qe_invalid;
9137
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags8,f))
9138 return qe_invalid;
9139
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags9,f))
9140 return qe_invalid;
9141
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags10,f))
9142 return qe_invalid;
9143
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags11,f))
9144 return qe_invalid;
9145 1294 }
9146
2/2
✓ Branch 0 taken 7308 times.
✓ Branch 1 taken 1072 times.
8380 if(scr_has_flags & SCRHAS_ENEMY)
9147 {
9148
2/2
✓ Branch 0 taken 10720 times.
✓ Branch 1 taken 1072 times.
11792 for(int32_t k=0; k<10; k++)
9149 {
9150
1/2
✓ Branch 0 taken 10720 times.
✗ Branch 1 not taken.
10720 if(!p_iputw(screen.enemy[k],f))
9151 return qe_invalid;
9152 10720 }
9153
1/2
✓ Branch 0 taken 1072 times.
✗ Branch 1 not taken.
1072 if(!p_putc(screen.pattern,f))
9154 return qe_invalid;
9155 1072 }
9156
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_CARRY)
9157 {
9158
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.noreset,f))
9159 return qe_invalid;
9160
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.nocarry,f))
9161 return qe_invalid;
9162
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.exstate_reset,f))
9163 return qe_invalid;
9164
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.exstate_carry,f))
9165 return qe_invalid;
9166
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.nextmap,f))
9167 return qe_invalid;
9168
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.nextscr,f))
9169 return qe_invalid;
9170 8380 }
9171
2/2
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 22 times.
8380 if(scr_has_flags & SCRHAS_SCRIPT)
9172 {
9173
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputw(screen.script,f))
9174 return qe_invalid;
9175
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_putc(screen.preloadscript,f))
9176 return qe_invalid;
9177
2/2
✓ Branch 0 taken 176 times.
✓ Branch 1 taken 22 times.
198 for ( int32_t q = 0; q < 8; q++ )
9178 {
9179
1/2
✓ Branch 0 taken 176 times.
✗ Branch 1 not taken.
176 if(!p_iputl(screen.screeninitd[q],f))
9180 return qe_invalid;
9181 176 }
9182 22 }
9183
2/2
✓ Branch 0 taken 5304 times.
✓ Branch 1 taken 3076 times.
8380 if(scr_has_flags & SCRHAS_SECRETS)
9184 {
9185
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9186 {
9187
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_iputw(screen.secretcombo[k],f))
9188 return qe_invalid;
9189 393728 }
9190
9191
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9192 {
9193
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_putc(screen.secretcset[k],f))
9194 return qe_invalid;
9195 393728 }
9196
9197
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9198 {
9199
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_putc(screen.secretflag[k],f))
9200 return qe_invalid;
9201 393728 }
9202 3076 }
9203
2/2
✓ Branch 0 taken 3020 times.
✓ Branch 1 taken 5360 times.
8380 if(scr_has_flags & SCRHAS_COMBOFLAG)
9204 {
9205
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9206 {
9207
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_iputw(screen.data[k],f))
9208 return qe_invalid;
9209 943360 }
9210
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9211 {
9212
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_putc(screen.sflag[k],f))
9213 return qe_invalid;
9214 943360 }
9215
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9216 {
9217
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_putc(screen.cset[k],f))
9218 return qe_invalid;
9219 943360 }
9220 5360 }
9221
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_MISC)
9222 {
9223
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.color,f))
9224 return qe_invalid;
9225
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.csensitive,f))
9226 return qe_invalid;
9227
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.oceansfx,f))
9228 return qe_invalid;
9229
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.bosssfx,f))
9230 return qe_invalid;
9231
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.secretsfx,f))
9232 return qe_invalid;
9233
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.holdupsfx,f))
9234 return qe_invalid;
9235
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.timedwarptics,f))
9236 return qe_invalid;
9237
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.screen_midi,f))
9238 return qe_invalid;
9239
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.lens_layer,f))
9240 return qe_invalid;
9241
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(!p_putc(screen.lens_show,f))
9242 return qe_invalid;
9243
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.lens_hide,f))
9244 return qe_invalid;
9245 8380 }
9246
9247 8380 dword numffc = screen.numFFC();
9248
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(numffc,f))
9249 return qe_invalid;
9250
2/2
✓ Branch 0 taken 245678 times.
✓ Branch 1 taken 8380 times.
254058 for(int32_t k=0; k<numffc; ++k)
9251 {
9252 245678 ffcdata const& tempffc = screen.ffcs[k];
9253
9254
1/2
✓ Branch 0 taken 245678 times.
✗ Branch 1 not taken.
245678 if(!p_iputw(tempffc.data,f))
9255 return qe_invalid;
9256
9257
2/2
✓ Branch 0 taken 2314 times.
✓ Branch 1 taken 243364 times.
245678 if(!tempffc.data) //don't save the rest of the ffc
9258 243364 continue;
9259
9260
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.cset,f))
9261 return qe_invalid;
9262
9263
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputw(tempffc.delay,f))
9264 return qe_invalid;
9265
9266
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.x,f))
9267 return qe_invalid;
9268
9269
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.y,f))
9270 return qe_invalid;
9271
9272
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.vx,f))
9273 return qe_invalid;
9274
9275
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.vy,f))
9276 return qe_invalid;
9277
9278
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.ax,f))
9279 return qe_invalid;
9280
9281
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.ay,f))
9282 return qe_invalid;
9283
9284
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.link,f))
9285 return qe_invalid;
9286
9287
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.hit_width,f))
9288 return qe_invalid;
9289
9290
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.hit_height,f))
9291 return qe_invalid;
9292
9293
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.txsz,f))
9294 return qe_invalid;
9295
9296
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.tysz,f))
9297 return qe_invalid;
9298
9299
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.flags,f))
9300 return qe_invalid;
9301
9302
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputw(tempffc.script,f))
9303 return qe_invalid;
9304
9305
2/2
✓ Branch 0 taken 18512 times.
✓ Branch 1 taken 2314 times.
20826 for(auto q = 0; q < 8; ++q)
9306 {
9307
1/2
✓ Branch 0 taken 18512 times.
✗ Branch 1 not taken.
18512 if(!p_iputl(tempffc.initd[q],f))
9308 return qe_invalid;
9309 18512 }
9310
9311
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.layer,f))
9312 return qe_invalid;
9313 2314 }
9314
9315
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putlstr(screen.usr_notes, f))
9316 return qe_invalid;
9317
9318
2/2
✓ Branch 0 taken 8374 times.
✓ Branch 1 taken 6 times.
8380 if (screen.flags10 & fSCREEN_GRAVITY)
9319 {
9320
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!p_iputzf(screen.screen_gravity, f))
9321 return qe_invalid;
9322
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!p_iputzf(screen.screen_terminal_v, f))
9323 return qe_invalid;
9324 6 }
9325
9326 8380 return qe_OK;
9327 12784 }
9328
9329 9 int32_t writemaps(PACKFILE *f, zquestheader *)
9330 {
9331 9 dword section_id=ID_MAPS;
9332 9 dword section_version=V_MAPS;
9333 9 dword section_size = 0;
9334
9335 //section id
9336
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9337 {
9338 new_return(1);
9339 }
9340
9341 //section version info
9342
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9343 {
9344 new_return(2);
9345 }
9346
9347
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
9348 {
9349 new_return(3);
9350 }
9351
9352
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9353 {
9354 18 fake_pack_writing=(writecycle==0);
9355
9356 //section size
9357
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
9358 {
9359 new_return(4);
9360 }
9361
9362 18 writesize=0;
9363
9364
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(map_count,f))
9365 {
9366 new_return(5);
9367 }
9368 18 map_infos.resize(map_count);
9369
4/4
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 100 times.
✓ Branch 2 taken 100 times.
✓ Branch 3 taken 18 times.
118 for(int32_t i=0; i<map_count && i<MAXMAPS; i++)
9370 {
9371 100 byte valid = 0;
9372
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1282 times.
1288 for(int32_t j=0; j<MAPSCRS; j++)
9373 {
9374
1/2
✓ Branch 0 taken 1282 times.
✗ Branch 1 not taken.
1282 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
9375 break;
9376 1282 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
9377
2/2
✓ Branch 0 taken 94 times.
✓ Branch 1 taken 1188 times.
1282 if (screen.is_valid())
9378 {
9379 94 valid = 1;
9380 94 break;
9381 }
9382 1188 }
9383
1/2
✓ Branch 0 taken 100 times.
✗ Branch 1 not taken.
100 if(!p_putc(valid,f))
9384 {
9385 new_return(6);
9386 }
9387
2/2
✓ Branch 0 taken 94 times.
✓ Branch 1 taken 6 times.
100 if(!valid) continue;
9388
9389 { //per-map info
9390 94 auto const& mapinf = map_infos[i];
9391
2/2
✓ Branch 0 taken 564 times.
✓ Branch 1 taken 94 times.
658 for(int q = 0; q < 6; ++q)
9392 {
9393
1/2
✓ Branch 0 taken 564 times.
✗ Branch 1 not taken.
564 if(!p_iputw(mapinf.autolayers[q],f))
9394 new_return(7);
9395 564 }
9396
1/2
✓ Branch 0 taken 94 times.
✗ Branch 1 not taken.
94 if(!p_iputw(mapinf.autopalette,f))
9397 new_return(9);
9398
9399
9400
2/2
✓ Branch 0 taken 752 times.
✓ Branch 1 taken 94 times.
846 for(int32_t j=0; j<8; j++)
9401 {
9402
2/2
✓ Branch 0 taken 752 times.
✓ Branch 1 taken 6016 times.
6768 for(int32_t k=0; k<8; k++)
9403 {
9404
1/2
✓ Branch 0 taken 6016 times.
✗ Branch 1 not taken.
6016 if(!p_putc(Regions[i].region_ids[j][k],f))
9405 {
9406 new_return(8);
9407 }
9408 6016 }
9409 752 }
9410 }
9411
9412
2/2
✓ Branch 0 taken 12784 times.
✓ Branch 1 taken 94 times.
12878 for(int32_t j=0; j<MAPSCRS; j++)
9413 12784 writemapscreen(f,i,j);
9414 94 }
9415
9416
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
9417 {
9418 9 section_size=writesize;
9419 9 }
9420 18 }
9421
9422
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
9423 {
9424 char ebuf[80];
9425 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9426 jwin_alert("Error: writemaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9427 }
9428
9429 9 new_return(0);
9430 }
9431
9432 460 int32_t writecombo_triggers_loop(PACKFILE *f, word section_version, combo_trigger const& tmp_trig)
9433 {
9434
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putcstr(tmp_trig.label,f))
9435 return 22;
9436
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putbitstr(tmp_trig.trigger_flags,f))
9437 return 22;
9438
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.triggerlevel,f))
9439 return 23;
9440
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.triggerbtn,f))
9441 return 34;
9442
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.triggeritem,f))
9443 return 35;
9444
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigtimer,f))
9445 return 36;
9446
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigsfx,f))
9447 return 37;
9448
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.trigchange,f))
9449 return 38;
9450
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigprox,f))
9451 return 39;
9452
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigctr,f))
9453 return 40;
9454
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.trigctramnt,f))
9455 return 41;
9456
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.triglbeam,f))
9457 return 42;
9458
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigcschange,f))
9459 return 43;
9460
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.spawnitem,f))
9461 return 44;
9462
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.spawnenemy,f))
9463 return 45;
9464
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.exstate,f))
9465 return 46;
9466
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.spawnip,f))
9467 return 47;
9468
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigcopycat,f))
9469 return 48;
9470
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigcooldown,f))
9471 return 49;
9472
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.prompt_cid,f))
9473 return 50;
9474
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.prompt_cs,f))
9475 return 51;
9476
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.prompt_x,f))
9477 return 52;
9478
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.prompt_y,f))
9479 return 53;
9480
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trig_lstate,f))
9481 return 69;
9482
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trig_gstate,f))
9483 return 70;
9484
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.trig_statetime,f))
9485 return 71;
9486
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_genscr,f))
9487 return 72;
9488
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trig_group,f))
9489 return 76;
9490
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_group_val,f))
9491 return 77;
9492
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.exdoor_dir,f))
9493 return 89;
9494
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.exdoor_ind,f))
9495 return 90;
9496
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_levelitems,f))
9497 return 91;
9498
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigdmlevel,f))
9499 return 92;
9500
2/2
✓ Branch 0 taken 1380 times.
✓ Branch 1 taken 460 times.
1840 for(int q = 0; q < 3; ++q)
9501
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1380 times.
1380 if(!p_iputw(tmp_trig.trigtint[q],f))
9502 return 93;
9503
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.triglvlpalette,f))
9504 return 94;
9505
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trigbosspalette,f))
9506 return 95;
9507
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trigquaketime,f))
9508 return 96;
9509
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trigwavytime,f))
9510 return 97;
9511
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trig_swjinxtime,f))
9512 return 98;
9513
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trig_itmjinxtime,f))
9514 return 99;
9515
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_stuntime,f))
9516 return 100;
9517
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trig_bunnytime,f))
9518 return 101;
9519
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.trig_pushtime,f))
9520 return 102;
9521
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_iputw(tmp_trig.trig_shieldjinxtime, f))
9522 return 103;
9523
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.req_level_state, f))
9524 return 104;
9525
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.unreq_level_state, f))
9526 return 105;
9527
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putbitstr(tmp_trig.req_global_state, f))
9528 return 106;
9529
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putbitstr(tmp_trig.unreq_global_state, f))
9530 return 107;
9531
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.fail_prompt_cid, f))
9532 return 108;
9533
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.fail_prompt_cs, f))
9534 return 109;
9535
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.trig_msgstr, f))
9536 return 110;
9537
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.fail_msgstr, f))
9538 return 111;
9539
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputzf(tmp_trig.player_bounce, f))
9540 return 112;
9541
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.req_player_z, f))
9542 return 113;
9543
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.req_player_dir, f))
9544 return 114;
9545
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.dest_player_x, f))
9546 return 115;
9547
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.dest_player_y, f))
9548 return 116;
9549
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.dest_player_z, f))
9550 return 117;
9551
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputzf(tmp_trig.req_player_jump, f))
9552 return 118;
9553
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.req_player_x, f))
9554 return 119;
9555
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.req_player_y, f))
9556 return 120;
9557
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.dest_player_dir, f))
9558 return 121;
9559
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.force_ice_combo, f))
9560 return 122;
9561
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.force_ice_vx, f))
9562 return 123;
9563
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputzf(tmp_trig.force_ice_vy, f))
9564 return 124;
9565
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.trig_gravity, f))
9566 return 125;
9567
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.trig_terminal_v, f))
9568 return 126;
9569 460 return 0;
9570 460 }
9571 258906 int32_t writecombo_loop(PACKFILE *f, word section_version, newcombo const& tmp_cmb)
9572 {
9573 //Check what needs writing
9574 258906 word combo_has_flags = 0;
9575
2/2
✓ Branch 0 taken 255716 times.
✓ Branch 1 taken 2056150 times.
2311866 for(auto q = 0; q < 8; ++q)
9576 {
9577
4/4
✓ Branch 0 taken 2054470 times.
✓ Branch 1 taken 1680 times.
✓ Branch 2 taken 1028294 times.
✓ Branch 3 taken 1382 times.
3085826 if(tmp_cmb.attribytes[q] || tmp_cmb.attrishorts[q]
9578
4/4
✓ Branch 0 taken 2054342 times.
✓ Branch 1 taken 128 times.
✓ Branch 2 taken 1029676 times.
✓ Branch 3 taken 1024666 times.
2054470 || (q < 4 && tmp_cmb.attributes[q]))
9579 {
9580 3190 combo_has_flags |= CHAS_ATTRIB;
9581 3190 break;
9582 }
9583 2052960 }
9584
2/2
✓ Branch 0 taken 258446 times.
✓ Branch 1 taken 460 times.
258906 if (!tmp_cmb.triggers.empty())
9585 460 combo_has_flags |= CHAS_TRIG;
9586
4/4
✓ Branch 0 taken 258628 times.
✓ Branch 1 taken 278 times.
✓ Branch 2 taken 20 times.
✓ Branch 3 taken 258608 times.
258906 if(tmp_cmb.usrflags || tmp_cmb.genflags)
9587 298 combo_has_flags |= CHAS_FLAG;
9588
6/6
✓ Branch 0 taken 251806 times.
✓ Branch 1 taken 7100 times.
✓ Branch 2 taken 231382 times.
✓ Branch 3 taken 20424 times.
✓ Branch 4 taken 532 times.
✓ Branch 5 taken 230732 times.
490170 if(tmp_cmb.frames || tmp_cmb.speed || tmp_cmb.nextcombo
9589
6/6
✓ Branch 0 taken 231358 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 231320 times.
✓ Branch 3 taken 38 times.
✓ Branch 4 taken 231264 times.
✓ Branch 5 taken 56 times.
231382 || tmp_cmb.nextcset || tmp_cmb.skipanim || tmp_cmb.skipanimy
9590
1/2
✓ Branch 0 taken 231264 times.
✗ Branch 1 not taken.
231264 || tmp_cmb.animflags)
9591 28174 combo_has_flags |= CHAS_ANIM;
9592
3/4
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 258900 times.
258906 if(tmp_cmb.script || tmp_cmb.label.size())
9593 6 combo_has_flags |= CHAS_SCRIPT;
9594
2/2
✓ Branch 0 taken 258900 times.
✓ Branch 1 taken 2071200 times.
2330100 else for(auto q = 0; q < 8; ++q)
9595 {
9596
1/2
✓ Branch 0 taken 2071200 times.
✗ Branch 1 not taken.
2071200 if(tmp_cmb.initd[q])
9597 {
9598 combo_has_flags |= CHAS_SCRIPT;
9599 break;
9600 }
9601 2071200 }
9602
5/6
✓ Branch 0 taken 176904 times.
✓ Branch 1 taken 82002 times.
✓ Branch 2 taken 176392 times.
✓ Branch 3 taken 512 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 176392 times.
435298 if(tmp_cmb.o_tile || tmp_cmb.flip || tmp_cmb.walk != 0xF0
9603
2/4
✓ Branch 0 taken 176392 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 176392 times.
✗ Branch 3 not taken.
176392 || tmp_cmb.type || tmp_cmb.csets)
9604 82514 combo_has_flags |= CHAS_BASIC;
9605
3/4
✓ Branch 0 taken 258898 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
517802 if(tmp_cmb.liftcmb || tmp_cmb.liftcs || tmp_cmb.liftdmg
9606
3/6
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258898 times.
✗ Branch 5 not taken.
258898 || tmp_cmb.liftlvl || tmp_cmb.liftitm || tmp_cmb.liftflags
9607
4/6
✓ Branch 0 taken 258896 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258896 times.
✗ Branch 5 not taken.
258898 || tmp_cmb.liftgfx || tmp_cmb.liftsprite || tmp_cmb.liftsfx
9608
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.liftundercmb || tmp_cmb.liftundercs
9609
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.liftbreaksprite!=-1 || tmp_cmb.liftbreaksfx
9610
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.lifthei!=8 || tmp_cmb.lifttime!=16
9611
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.lift_parent_item || !tmp_cmb.lift_weap_data.is_blank())
9612 10 combo_has_flags |= CHAS_LIFT;
9613
2/4
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258906 times.
✗ Branch 3 not taken.
515612 if(tmp_cmb.speed_mult != 1 || tmp_cmb.speed_div != 1 || tmp_cmb.speed_add
9614
7/10
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258902 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 258898 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 258898 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 258898 times.
✗ Branch 9 not taken.
258906 || tmp_cmb.sfx_appear || tmp_cmb.sfx_disappear || tmp_cmb.sfx_loop || tmp_cmb.sfx_walking || tmp_cmb.sfx_standing
9615
5/10
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258898 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 258898 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 258898 times.
✗ Branch 9 not taken.
258898 || tmp_cmb.spr_appear || tmp_cmb.spr_disappear || tmp_cmb.spr_walking || tmp_cmb.spr_standing || tmp_cmb.sfx_tap
9616
6/10
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 256706 times.
✓ Branch 3 taken 2192 times.
✓ Branch 4 taken 256706 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 256706 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 256706 times.
✗ Branch 9 not taken.
258898 || tmp_cmb.sfx_landing || tmp_cmb.spr_falling || tmp_cmb.spr_drowning || tmp_cmb.spr_lava_drowning || tmp_cmb.sfx_falling
9617
4/8
✓ Branch 0 taken 256706 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 256706 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 256706 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 256706 times.
✗ Branch 7 not taken.
256706 || tmp_cmb.sfx_drowning || tmp_cmb.sfx_lava_drowning || tmp_cmb.z_height || tmp_cmb.z_step_height
9618
1/2
✓ Branch 0 taken 256706 times.
✗ Branch 1 not taken.
256706 || tmp_cmb.dive_under_level)
9619 258906 combo_has_flags |= CHAS_GENERAL;
9620
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!tmp_cmb.misc_weap_data.is_blank())
9621 combo_has_flags |= CHAS_MISC_WEAP_DATA;
9622
9623
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(combo_has_flags,f))
9624 {
9625 return 50;
9626 }
9627
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!combo_has_flags) return 0; //Valid, done writing
9628 //Write the combo
9629
2/2
✓ Branch 0 taken 176392 times.
✓ Branch 1 taken 82514 times.
258906 if(combo_has_flags&CHAS_BASIC)
9630 {
9631
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_iputl(tmp_cmb.o_tile,f))
9632 return 6;
9633
9634
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.flip,f))
9635 return 7;
9636
9637
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.walk,f))
9638 return 8;
9639
9640
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.type,f))
9641 return 9;
9642
9643
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.flag,f))
9644 return 15;
9645
9646
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.csets,f))
9647 return 10;
9648 82514 }
9649
2/2
✓ Branch 0 taken 258900 times.
✓ Branch 1 taken 6 times.
258906 if(combo_has_flags&CHAS_SCRIPT)
9650 {
9651 6 p_putcstr(tmp_cmb.label, f);
9652
9653
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(tmp_cmb.script,f))
9654 return 26;
9655
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for ( int32_t q = 0; q < 8; q++ )
9656
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(tmp_cmb.initd[q],f))
9657 return 27;
9658 6 }
9659
2/2
✓ Branch 0 taken 230732 times.
✓ Branch 1 taken 28174 times.
258906 if(combo_has_flags&CHAS_ANIM)
9660 {
9661
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.frames,f))
9662 return 11;
9663
9664
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.speed,f))
9665 return 12;
9666
9667
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_iputw(tmp_cmb.nextcombo,f))
9668 return 13;
9669
9670
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.nextcset,f))
9671 return 14;
9672
9673
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.skipanim,f))
9674 return 16;
9675
9676
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.skipanimy,f))
9677 return 18;
9678
9679
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.animflags,f))
9680 return 19;
9681 28174 }
9682
2/2
✓ Branch 0 taken 255716 times.
✓ Branch 1 taken 3190 times.
258906 if(combo_has_flags&CHAS_ATTRIB)
9683 {
9684
2/2
✓ Branch 0 taken 12760 times.
✓ Branch 1 taken 3190 times.
15950 for ( int32_t q = 0; q < 4; q++ )
9685
1/2
✓ Branch 0 taken 12760 times.
✗ Branch 1 not taken.
12760 if(!p_iputl(tmp_cmb.attributes[q],f))
9686 return 20;
9687
2/2
✓ Branch 0 taken 25520 times.
✓ Branch 1 taken 3190 times.
28710 for ( int32_t q = 0; q < 8; q++ )
9688
1/2
✓ Branch 0 taken 25520 times.
✗ Branch 1 not taken.
25520 if(!p_putc(tmp_cmb.attribytes[q],f))
9689 return 25;
9690
2/2
✓ Branch 0 taken 25520 times.
✓ Branch 1 taken 3190 times.
28710 for ( int32_t q = 0; q < 8; q++ ) //I also added attrishorts -Dimi
9691
1/2
✓ Branch 0 taken 25520 times.
✗ Branch 1 not taken.
25520 if(!p_iputw(tmp_cmb.attrishorts[q],f))
9692 return 32;
9693 3190 }
9694
2/2
✓ Branch 0 taken 258608 times.
✓ Branch 1 taken 298 times.
258906 if(combo_has_flags&CHAS_FLAG)
9695 {
9696
1/2
✓ Branch 0 taken 298 times.
✗ Branch 1 not taken.
298 if(!p_iputl(tmp_cmb.usrflags,f))
9697 return 21;
9698
1/2
✓ Branch 0 taken 298 times.
✗ Branch 1 not taken.
298 if(!p_iputw(tmp_cmb.genflags,f))
9699 return 33;
9700 298 }
9701
2/2
✓ Branch 0 taken 258446 times.
✓ Branch 1 taken 460 times.
258906 if(combo_has_flags&CHAS_TRIG)
9702 {
9703
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 byte sz = zc_min(tmp_cmb.triggers.size(), 255);
9704
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(sz,f))
9705 return 34;
9706
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 460 times.
920 for(byte q = 0; q < sz; ++q)
9707 {
9708 460 auto ret = writecombo_triggers_loop(f, section_version, tmp_cmb.triggers[q]);
9709
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(ret) return ret;
9710 460 }
9711
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.only_gentrig,f))
9712 return 35;
9713 460 }
9714
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 258906 times.
258906 if(combo_has_flags&CHAS_LIFT)
9715 {
9716
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(tmp_cmb.liftcmb,f))
9717 return 54;
9718
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftcs,f))
9719 return 55;
9720
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(tmp_cmb.liftundercmb,f))
9721 return 56;
9722
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftundercs,f))
9723 return 57;
9724
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftdmg,f))
9725 return 58;
9726
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftlvl,f))
9727 return 59;
9728
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftitm,f))
9729 return 60;
9730
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftflags,f))
9731 return 61;
9732
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftgfx,f))
9733 return 62;
9734
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftsprite,f))
9735 return 63;
9736
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftsfx,f))
9737 return 64;
9738
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(tmp_cmb.liftbreaksprite,f))
9739 return 65;
9740
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftbreaksfx,f))
9741 return 66;
9742
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.lifthei,f))
9743 return 67;
9744
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.lifttime,f))
9745 return 68;
9746
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.lift_parent_item,f))
9747 return 78;
9748
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 258906 times.
258906 if(auto ret = write_weap_data(tmp_cmb.lift_weap_data, f))
9749 return ret;
9750 258906 }
9751
2/2
✓ Branch 0 taken 256706 times.
✓ Branch 1 taken 2200 times.
258906 if(combo_has_flags&CHAS_GENERAL)
9752 {
9753
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.speed_mult,f))
9754 return 73;
9755
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.speed_div,f))
9756 return 74;
9757
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_iputzf(tmp_cmb.speed_add,f))
9758 return 75;
9759
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_appear,f))
9760 return 79;
9761
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_disappear,f))
9762 return 80;
9763
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_loop,f))
9764 return 81;
9765
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_walking,f))
9766 return 82;
9767
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_standing,f))
9768 return 83;
9769
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_appear,f))
9770 return 84;
9771
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_disappear,f))
9772 return 85;
9773
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_walking,f))
9774 return 86;
9775
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_standing,f))
9776 return 87;
9777
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_tap,f))
9778 return 88;
9779
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_landing,f))
9780 return 89;
9781
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_falling,f))
9782 return 90;
9783
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_drowning,f))
9784 return 91;
9785
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_lava_drowning,f))
9786 return 92;
9787
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_falling,f))
9788 return 93;
9789
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_drowning,f))
9790 return 94;
9791
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_lava_drowning,f))
9792 return 95;
9793
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_iputzf(tmp_cmb.z_height,f))
9794 return 96;
9795
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_iputzf(tmp_cmb.z_step_height,f))
9796 return 97;
9797
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2200 times.
2200 if(!p_putc(tmp_cmb.dive_under_level,f))
9798 return 98;
9799 2200 }
9800
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(combo_has_flags&CHAS_MISC_WEAP_DATA)
9801 {
9802 if(auto ret = write_weap_data(tmp_cmb.misc_weap_data, f))
9803 return ret;
9804 }
9805 258906 return 0;
9806 258906 }
9807
9808 9 int32_t writecombos(PACKFILE *f, word version, word build, word start_combo, word max_combos)
9809 {
9810 //these are here to bypass compiler warnings about unused arguments
9811 9 version=version;
9812 9 build=build;
9813
9814 word combos_used;
9815 9 dword section_id=ID_COMBOS;
9816 9 dword section_version=V_COMBOS;
9817 // dword section_size=0;
9818 9 combos_used = count_combos()-start_combo;
9819
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 combos_used = zc_min(combos_used, max_combos);
9820
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 combos_used = zc_min(combos_used, MAXCOMBOS);
9821 9 dword section_size = 0;
9822
9823 //section id
9824
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9825 {
9826 new_return(1);
9827 }
9828
9829 //section version info
9830
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9831 {
9832 new_return(2);
9833 }
9834
9835
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
9836 {
9837 new_return(3);
9838 }
9839
9840
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9841 {
9842 18 fake_pack_writing=(writecycle==0);
9843
9844 //section size
9845
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
9846 {
9847 new_return(4);
9848 }
9849
9850 18 writesize=0;
9851
9852 //finally... section data
9853 18 combos_used=count_combos()-start_combo;
9854
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 combos_used=zc_min(combos_used, max_combos);
9855
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 combos_used=zc_min(combos_used, MAXCOMBOS);
9856
9857
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(combos_used,f))
9858 {
9859 new_return(5);
9860 }
9861
9862 18 size_t end_combo = start_combo+combos_used;
9863
2/2
✓ Branch 0 taken 258906 times.
✓ Branch 1 taken 18 times.
258924 for(size_t q = start_combo; q < end_combo; ++q)
9864 {
9865 258906 auto ret = writecombo_loop(f, section_version, combobuf[q]);
9866
1/4
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
258906 if(ret) new_return(ret);
9867 258906 }
9868
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
9869 {
9870 9 section_size=writesize;
9871 9 }
9872 18 }
9873
9874
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
9875 {
9876 char ebuf[80];
9877 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9878 jwin_alert("Error: writecombos()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9879 }
9880
9881 9 new_return(0);
9882 9 }
9883
9884 9 int32_t writecomboaliases(PACKFILE *f, word version, word build)
9885 {
9886 //these are here to bypass compiler warnings about unused arguments
9887 9 version=version;
9888 9 build=build;
9889
9890 9 dword section_id=ID_COMBOALIASES;
9891 9 dword section_version=V_COMBOALIASES;
9892 9 dword section_size=0;
9893
9894 //section id
9895
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9896 {
9897 new_return(1);
9898 }
9899
9900 //section version info
9901
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9902 {
9903 new_return(2);
9904 }
9905
9906
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
9907 {
9908 new_return(3);
9909 }
9910
9911
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9912 {
9913 18 fake_pack_writing=(writecycle==0);
9914
9915 //section size
9916
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
9917 {
9918 new_return(4);
9919 }
9920
9921 18 writesize=0;
9922
9923 //finally... section data
9924
2/2
✓ Branch 0 taken 147456 times.
✓ Branch 1 taken 18 times.
147474 for(int32_t j=0; j<MAXCOMBOALIASES; j++)
9925 {
9926
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_iputw(combo_aliases[j].combo,f))
9927 {
9928 new_return(5);
9929 }
9930
9931
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].cset,f))
9932 {
9933 new_return(6);
9934 }
9935
9936 147456 int32_t count = ((combo_aliases[j].width+1)*(combo_aliases[j].height+1))*(comboa_lmasktotal(combo_aliases[j].layermask)+1);
9937
9938
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].width,f))
9939 {
9940 new_return(7);
9941 }
9942
9943
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].height,f))
9944 {
9945 new_return(8);
9946 }
9947
9948
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].layermask,f))
9949 {
9950 new_return(9);
9951 }
9952
9953
2/2
✓ Branch 0 taken 149596 times.
✓ Branch 1 taken 147456 times.
297052 for(int32_t k=0; k<count; k++)
9954 {
9955
1/2
✓ Branch 0 taken 149596 times.
✗ Branch 1 not taken.
149596 if(!p_iputw(combo_aliases[j].combos[k],f))
9956 {
9957 new_return(10);
9958 }
9959 149596 }
9960
9961
2/2
✓ Branch 0 taken 149596 times.
✓ Branch 1 taken 147456 times.
297052 for(int32_t k=0; k<count; k++)
9962 {
9963
1/2
✓ Branch 0 taken 149596 times.
✗ Branch 1 not taken.
149596 if(!p_putc(combo_aliases[j].csets[k],f))
9964 {
9965 new_return(11);
9966 }
9967 149596 }
9968 147456 }
9969
9970 //Combo pools!
9971 int16_t num_cpools;
9972
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 147452 times.
147468 for(num_cpools = MAXCOMBOPOOLS-1; num_cpools >= 0; --num_cpools)
9973 {
9974
2/2
✓ Branch 0 taken 147450 times.
✓ Branch 1 taken 2 times.
147452 if(combo_pools[num_cpools].valid()) //found a used pool
9975 {
9976 2 ++num_cpools;
9977 2 break;
9978 }
9979 147450 }
9980
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 16 times.
18 if(num_cpools < 0) num_cpools = 0;
9981
9982
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(num_cpools,f))
9983 {
9984 new_return(12);
9985 }
9986
9987
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 18 times.
24 for(auto cp = 0; cp < num_cpools; ++cp)
9988 {
9989 6 combo_pool const& pool = combo_pools[cp];
9990 6 int32_t num_combos = pool.combos.size();
9991
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputl(num_combos,f))
9992 {
9993 new_return(13);
9994 }
9995
9996
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 6 times.
32 for(auto q = 0; q < num_combos; ++q)
9997 {
9998 26 cpool_entry const& entry = pool.combos.at(q);
9999
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputl(entry.cid,f))
10000 {
10001 new_return(14);
10002 }
10003
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_putc(entry.cset,f))
10004 {
10005 new_return(15);
10006 }
10007
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputw(entry.quant,f))
10008 {
10009 new_return(16);
10010 }
10011 26 }
10012 6 }
10013
10014 //Autocombos!
10015 int16_t num_cautos;
10016
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 147456 times.
147474 for (num_cautos = MAXAUTOCOMBOS - 1; num_cautos >= 0; --num_cautos)
10017 {
10018
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if (combo_autos[num_cautos].valid()) //found a used autocombo
10019 {
10020 ++num_cautos;
10021 break;
10022 }
10023 147456 }
10024
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (num_cautos < 0) num_cautos = 0;
10025
10026
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(num_cautos, f))
10027 {
10028 new_return(17);
10029 }
10030
10031
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 for (auto ca = 0; ca < num_cautos; ++ca)
10032 {
10033 combo_auto const& cauto = combo_autos[ca];
10034 if (!p_putc(cauto.getType(), f))
10035 {
10036 new_return(18);
10037 }
10038 if (!p_iputl(cauto.getIconDisplay(), f))
10039 {
10040 new_return(19);
10041 }
10042 if (!p_iputl(cauto.getEraseCombo(), f))
10043 {
10044 new_return(20);
10045 }
10046 if (!p_putc(cauto.getFlags(), f))
10047 {
10048 new_return(21);
10049 }
10050 if (!p_putc(cauto.getArg(), f))
10051 {
10052 new_return(22);
10053 }
10054 int32_t num_combos = cauto.combos.size();
10055 if (!p_iputl(num_combos, f))
10056 {
10057 new_return(23);
10058 }
10059
10060 for (auto q = 0; q < num_combos; ++q)
10061 {
10062 autocombo_entry const& entry = cauto.combos.at(q);
10063 if (!p_putc(entry.ctype, f))
10064 {
10065 new_return(24);
10066 }
10067 if (!p_iputl(entry.cid, f))
10068 {
10069 new_return(25);
10070 }
10071 }
10072 }
10073
10074
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10075 {
10076 9 section_size=writesize;
10077 9 }
10078 18 }
10079
10080
10081
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10082 {
10083 char ebuf[80];
10084 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10085 jwin_alert("Error: writecomboaliases()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10086 }
10087
10088 9 new_return(0);
10089 }
10090
10091 9 int32_t writecolordata(PACKFILE *f, word version, word build, word start_cset, word max_csets)
10092 {
10093 //these are here to bypass compiler warnings about unused arguments
10094 9 version=version;
10095 9 build=build;
10096 9 start_cset=start_cset;
10097 9 max_csets=max_csets;
10098
10099 9 dword section_id=ID_CSETS;
10100 9 dword section_version=V_CSETS;
10101 9 int32_t palcycles = count_palcycles(&QMisc);
10102 // int32_t palcyccount = count_palcycles(&QMisc);
10103 9 dword section_size = 0;
10104
10105 //section id
10106
10107
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10108 {
10109 new_return(1);
10110 }
10111
10112 //section version info
10113
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10114 {
10115 new_return(2);
10116 }
10117
10118
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10119 {
10120 new_return(3);
10121 }
10122
10123
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10124 {
10125 18 fake_pack_writing=(writecycle==0);
10126
10127 //section size
10128
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10129 {
10130 new_return(4);
10131 }
10132
10133 18 writesize=0;
10134
10135 //finally... section data
10136
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(colordata,psTOTAL255,f))
10137 {
10138 new_return(5);
10139 }
10140
10141
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(palnames,MAXLEVELS*PALNAMESIZE,f))
10142 {
10143 new_return(6);
10144 }
10145
10146
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(palcycles,f))
10147 {
10148 new_return(15);
10149 }
10150
10151
2/2
✓ Branch 0 taken 550 times.
✓ Branch 1 taken 18 times.
568 for(int32_t i=0; i<palcycles; i++)
10152 {
10153
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10154 {
10155
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].first,f))
10156 {
10157 new_return(16);
10158 }
10159 1650 }
10160
10161
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10162 {
10163
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].count,f))
10164 {
10165 new_return(17);
10166 }
10167 1650 }
10168
10169
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10170 {
10171
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].speed,f))
10172 {
10173 new_return(18);
10174 }
10175 1650 }
10176 550 }
10177
10178
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10179 {
10180 9 section_size=writesize;
10181 9 }
10182 18 }
10183
10184
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10185 {
10186 char ebuf[80];
10187 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10188 jwin_alert("Error: writecolordata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10189 }
10190
10191 9 new_return(0);
10192 }
10193
10194 9 int32_t writestrings(PACKFILE *f, word version, word build, word start_msgstr, word max_msgstrs)
10195 {
10196 //these are here to bypass compiler warnings about unused arguments
10197 9 version=version;
10198 9 build=build;
10199 9 start_msgstr=start_msgstr;
10200 9 max_msgstrs=max_msgstrs;
10201
10202 9 dword section_id=ID_STRINGS;
10203 9 dword section_version=V_STRINGS;
10204 9 dword section_size = 0;
10205
10206 //section id
10207
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10208 {
10209 new_return(1);
10210 }
10211
10212 //section version info
10213
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10214 {
10215 new_return(2);
10216 }
10217
10218
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10219 {
10220 new_return(3);
10221 }
10222
10223
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10224 {
10225 18 fake_pack_writing=(writecycle==0);
10226
10227 //section size
10228
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10229 {
10230 new_return(4);
10231 }
10232
10233 18 writesize=0;
10234
10235 //finally... section data
10236
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(msg_count,f))
10237 {
10238 return qe_invalid;
10239 }
10240
10241
2/2
✓ Branch 0 taken 836 times.
✓ Branch 1 taken 18 times.
854 for(int32_t i=0; i<msg_count; i++)
10242 {
10243 836 MsgStrings[i].ensureAsciiEncoding();
10244 836 int32_t sz = MsgStrings[i].s.size();
10245
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(sz > 8192) sz = 8192;
10246
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(sz, f))
10247 {
10248 return qe_invalid;
10249 }
10250
10251 836 char const* tmpstr = MsgStrings[i].s.c_str();
10252
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 836 times.
836 if (sz > 0)
10253 {
10254
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if (!pfwrite((void*)tmpstr,sz, f))
10255 {
10256 return qe_invalid;
10257 }
10258 836 }
10259
10260
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].nextstring,f))
10261 {
10262 return qe_invalid;
10263 }
10264
10265
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(MsgStrings[i].tile,f))
10266 {
10267 return qe_invalid;
10268 }
10269
10270
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].cset,f))
10271 {
10272 return qe_invalid;
10273 }
10274
10275
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].trans?1:0,f))
10276 {
10277 return qe_invalid;
10278 }
10279
10280
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].font,f))
10281 {
10282 return qe_invalid;
10283 }
10284
10285
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].x,f))
10286 {
10287 return qe_invalid;
10288 }
10289
10290
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].y,f))
10291 {
10292 return qe_invalid;
10293 }
10294
10295
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].w,f))
10296 {
10297 return qe_invalid;
10298 }
10299
10300
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].h,f))
10301 {
10302 return qe_invalid;
10303 }
10304
10305
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].hspace,f))
10306 {
10307 return qe_invalid;
10308 }
10309
10310
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].vspace,f))
10311 {
10312 return qe_invalid;
10313 }
10314
10315
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].stringflags,f))
10316 {
10317 return qe_invalid;
10318 }
10319
10320
2/2
✓ Branch 0 taken 3344 times.
✓ Branch 1 taken 836 times.
4180 for(int32_t q = 0; q < 4; ++q)
10321 {
10322
1/2
✓ Branch 0 taken 3344 times.
✗ Branch 1 not taken.
3344 if(!p_putc(MsgStrings[i].margins[q],f))
10323 {
10324 return qe_invalid;
10325 }
10326 3344 }
10327
10328
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(MsgStrings[i].portrait_tile,f))
10329 {
10330 return qe_invalid;
10331 }
10332
10333
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_cset,f))
10334 {
10335 return qe_invalid;
10336 }
10337
10338
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_x,f))
10339 {
10340 return qe_invalid;
10341 }
10342
10343
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_y,f))
10344 {
10345 return qe_invalid;
10346 }
10347
10348
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_tw,f))
10349 {
10350 return qe_invalid;
10351 }
10352
10353
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_th,f))
10354 {
10355 return qe_invalid;
10356 }
10357
10358
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].shadow_type,f))
10359 {
10360 return qe_invalid;
10361 }
10362
10363
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].shadow_color,f))
10364 {
10365 return qe_invalid;
10366 }
10367
10368
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].drawlayer,f))
10369 {
10370 return qe_invalid;
10371 }
10372
10373
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].sfx,f))
10374 {
10375 return qe_invalid;
10376 }
10377
10378
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].listpos,f))
10379 {
10380 return qe_invalid;
10381 }
10382 836 }
10383
10384
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10385 {
10386 9 section_size=writesize;
10387 9 }
10388 18 }
10389
10390
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10391 {
10392 char ebuf[80];
10393 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10394 jwin_alert("Error: writestrings()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10395 }
10396
10397 9 new_return(0);
10398 9 }
10399
10400 int32_t writestrings_text(PACKFILE *f)
10401 {
10402 std::map<int32_t, int32_t> msglistcache;
10403
10404 for(int32_t index = 1; index<msg_count; index++)
10405 {
10406 for(int32_t i=1; i<msg_count; i++)
10407 {
10408 if(MsgStrings[i].listpos==index)
10409 {
10410 msglistcache[index-1]=i;
10411 break;
10412 }
10413 }
10414 }
10415
10416 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10417 {
10418 fake_pack_writing=(writecycle==0);
10419 char ebuf[32];
10420
10421 sprintf(ebuf,"Total strings: %d\n", msg_count-1);
10422
10423 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10424 {
10425 return qe_invalid;
10426 }
10427
10428 for(int32_t i=1; i<msg_count; i++)
10429 {
10430 int32_t str = msglistcache[i-1];
10431
10432 if(!str)
10433 continue;
10434
10435 if(MsgStrings[str].nextstring != 0)
10436 sprintf(ebuf,"\n\n___%d(->%d)___\n", str,MsgStrings[str].nextstring);
10437 else
10438 sprintf(ebuf,"\n\n___%d___\n", str);
10439
10440 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10441 {
10442 return qe_invalid;
10443 }
10444
10445 std::string text = MsgStrings[str].serialize();
10446 if (!pfwrite(text.c_str(), text.size(), f))
10447 {
10448 return qe_invalid;
10449 }
10450 }
10451 }
10452
10453 new_return(0);
10454 }
10455
10456 1 int32_t writestrings_tsv(PACKFILE *f)
10457 {
10458 1 std::stringstream ss;
10459
10460
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::vector<std::pair<std::string, std::function<std::string(const MsgStr&)>>> fields = {
10461
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "message", [&](auto& msg){ return msg.serialize(); }},
10462
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "next", [](auto& msg){ return std::to_string(msg.nextstring); } },
10463
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "tile", [](auto& msg){ return std::to_string(msg.tile); } },
10464
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "cset", [](auto& msg){ return std::to_string(msg.cset); } },
10465
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "trans", [](auto& msg){ return std::to_string(msg.trans); } },
10466
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "font", [](auto& msg){ return std::to_string(msg.font); } },
10467
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "x", [](auto& msg){ return std::to_string(msg.x); } },
10468
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "y", [](auto& msg){ return std::to_string(msg.y); } },
10469
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "w", [](auto& msg){ return std::to_string(msg.w); } },
10470
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "h", [](auto& msg){ return std::to_string(msg.h); } },
10471
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "sfx", [](auto& msg){ return std::to_string(msg.sfx); } },
10472
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "pos", [](auto& msg){ return std::to_string(msg.listpos); } },
10473
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "vspace", [](auto& msg){ return std::to_string(msg.vspace); } },
10474
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "hspace", [](auto& msg){ return std::to_string(msg.hspace); } },
10475
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "flags", [](auto& msg){ return std::to_string(msg.stringflags); } },
10476
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "margin", [](auto& msg){ return fmt::format("{} {} {} {}", msg.margins[0], msg.margins[3], msg.margins[1], msg.margins[2]); } },
10477
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tile", [](auto& msg){ return std::to_string(msg.portrait_tile); } },
10478
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_cset", [](auto& msg){ return std::to_string(msg.portrait_cset); } },
10479
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_x", [](auto& msg){ return std::to_string(msg.portrait_x); } },
10480
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_y", [](auto& msg){ return std::to_string(msg.portrait_y); } },
10481
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tw", [](auto& msg){ return std::to_string(msg.portrait_tw); } },
10482
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_th", [](auto& msg){ return std::to_string(msg.portrait_th); } },
10483
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_type", [](auto& msg){ return std::to_string(msg.shadow_type); } },
10484
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_color", [](auto& msg){ return std::to_string(msg.shadow_color); } },
10485
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "drawlayer", [](auto& msg){ return std::to_string(msg.drawlayer); } },
10486 };
10487
10488
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 for (auto& [name, fn] : fields)
10489 {
10490
2/4
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
50 ss << name;
10491
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 1 times.
25 if (name == fields.back().first)
10492 1 break;
10493
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 ss << '\t';
10494 }
10495
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << '\n';
10496
10497 // First entry is a fake string, to help frame the lines. Should be helpful if manually editing these in a text editor or spreadsheet.
10498
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << "|IT'S DANGEROUS TO GO || ALONE! TAKE THIS. ||LOREM IPSUM LOREM IPSU|\n";
10499
10500
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 35 times.
36 for(int32_t i=1; i<msg_count; i++)
10501 {
10502 35 auto& msg = MsgStrings[i];
10503
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
1750 for (auto& [name, fn] : fields)
10504 {
10505
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 std::string text = fn(msg);
10506
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 ss << text;
10507
2/2
✓ Branch 0 taken 840 times.
✓ Branch 1 taken 35 times.
875 if (name == fields.back().first)
10508 35 break;
10509
1/2
✓ Branch 0 taken 840 times.
✗ Branch 1 not taken.
840 ss << '\t';
10510
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 840 times.
875 }
10511
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 ss << '\n';
10512 35 }
10513
10514
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::string text = ss.str();
10515
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (!pack_fwrite(text.c_str(), text.size(), f))
10516 {
10517 return qe_invalid;
10518 }
10519
10520 1 new_return(0);
10521 1 }
10522
10523 void parse_strings_tsv(std::string tsv)
10524 {
10525 std::map<std::string, std::function<void(MsgStr&, const std::string&)>> fields = {
10526 { "message", [](auto& msg, auto& text){ msg.setFromAsciiEncoding(text); } },
10527 { "next", [](auto& msg, auto& text){ msg.nextstring = std::stoi(text); } },
10528 { "tile", [](auto& msg, auto& text){ msg.tile = std::stoi(text); } },
10529 { "cset", [](auto& msg, auto& text){ msg.cset = std::stoi(text); } },
10530 { "trans", [](auto& msg, auto& text){ msg.trans = std::stoi(text); } },
10531 { "font", [](auto& msg, auto& text){ msg.font = std::stoi(text); } },
10532 { "x", [](auto& msg, auto& text){ msg.x = std::stoi(text); } },
10533 { "y", [](auto& msg, auto& text){ msg.y = std::stoi(text); } },
10534 { "w", [](auto& msg, auto& text){ msg.w = std::stoi(text); } },
10535 { "h", [](auto& msg, auto& text){ msg.h = std::stoi(text); } },
10536 { "sfx", [](auto& msg, auto& text){ msg.sfx = std::stoi(text); } },
10537 { "pos", [](auto& msg, auto& text){ msg.listpos = std::stoi(text); } },
10538 { "vspace", [](auto& msg, auto& text){ msg.vspace = std::stoi(text); } },
10539 { "hspace", [](auto& msg, auto& text){ msg.hspace = std::stoi(text); } },
10540 { "flags", [](auto& msg, auto& text){ msg.stringflags = std::stoi(text); } },
10541 { "margin", [&](auto& msg, auto& text){
10542 std::vector<std::string> strs;
10543 util::split(text, strs, ' ');
10544 if (strs.size() != 4)
10545 throw std::runtime_error("margin field must have 4 components");
10546 msg.margins[0] = std::stoi(strs[0]);
10547 msg.margins[1] = std::stoi(strs[1]);
10548 msg.margins[2] = std::stoi(strs[2]);
10549 msg.margins[3] = std::stoi(strs[3]);
10550 } },
10551 { "portrait_tile", [](auto& msg, auto& text){ msg.portrait_tile = std::stoi(text); } },
10552 { "portrait_cset", [](auto& msg, auto& text){ msg.portrait_cset = std::stoi(text); } },
10553 { "portrait_x", [](auto& msg, auto& text){ msg.portrait_x = std::stoi(text); } },
10554 { "portrait_y", [](auto& msg, auto& text){ msg.portrait_y = std::stoi(text); } },
10555 { "portrait_tw", [](auto& msg, auto& text){ msg.portrait_tw = std::stoi(text); } },
10556 { "portrait_th", [](auto& msg, auto& text){ msg.portrait_th = std::stoi(text); } },
10557 { "shadow_type", [](auto& msg, auto& text){ msg.shadow_type = std::stoi(text); } },
10558 { "shadow_color", [](auto& msg, auto& text){ msg.shadow_color = std::stoi(text); } },
10559 { "drawlayer", [](auto& msg, auto& text){ msg.drawlayer = std::stoi(text); } },
10560 };
10561
10562 std::vector<std::string> rows;
10563 util::split(tsv, rows, '\n');
10564 if (rows.size())
10565 {
10566 std::string last = rows.back();
10567 util::trimstr(last);
10568 if (last.empty())
10569 rows.pop_back();
10570 }
10571 if (rows.size() <= 1)
10572 throw std::runtime_error("missing header row");
10573
10574 std::vector<std::string> columns;
10575 util::split(rows[0], columns, '\t');
10576 for (auto name : columns)
10577 {
10578 if (!fields.contains(name))
10579 throw std::runtime_error(fmt::format("invalid field: {}", name));
10580 }
10581
10582 int start_index = 1;
10583 if (rows[start_index].find("||LOREM IPSUM") != std::string::npos)
10584 start_index += 1;
10585
10586 int num_strings = rows.size() - start_index + 1;
10587 if (num_strings > MAXMSGS-1)
10588 throw std::runtime_error(fmt::format("too many strings, max is {}", MAXMSGS-1));
10589
10590 std::vector<MsgStr> msgs;
10591 msgs.reserve(num_strings);
10592 for (int i = start_index; i < rows.size(); i++)
10593 {
10594 std::vector<std::string> strs;
10595 util::split(rows[i], strs, '\t');
10596 if (strs.size() != columns.size())
10597 throw std::runtime_error(fmt::format("row {} has {} fields, expected {}", i, strs.size(), columns.size()));
10598
10599 int j = 0;
10600 auto& msg = msgs.emplace_back();
10601 for (auto& name : columns)
10602 {
10603 auto& fn = fields[name];
10604 try
10605 {
10606 fn(msg, strs[j++]);
10607 }
10608 catch (std::exception& ex)
10609 {
10610 throw std::runtime_error(fmt::format("error parsing row {} field {}: {}", i, name, ex.what()));
10611 }
10612 }
10613 }
10614
10615 init_msgstrings(0, msgs.size());
10616 for (int i = 0; i < msgs.size(); i++)
10617 MsgStrings[i + 1] = msgs[i];
10618 msg_count = msgs.size() + 1;
10619 msglistcache.clear();
10620 }
10621
10622 bool isblanktile(tiledata *buf, int32_t i);
10623 9 int32_t writetiles(PACKFILE *f, word version, word build, int32_t start_tile, int32_t max_tiles)
10624 {
10625 //these are here to bypass compiler warnings about unused arguments
10626 9 version=version;
10627 9 build=build;
10628
10629 int32_t tiles_used;
10630 9 dword section_id=ID_TILES;
10631 9 dword section_version=V_TILES;
10632 9 al_trace("Counting tiles used\n");
10633 9 tiles_used = count_tiles(newtilebuf)-start_tile;
10634
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 tiles_used = zc_min(tiles_used, max_tiles);
10635
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 tiles_used = zc_min(tiles_used, NEWMAXTILES);
10636 9 al_trace("writetiles counted %dtiles used.\n",tiles_used);
10637 9 dword section_size = 0;
10638
10639 //section id
10640
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10641 {
10642 new_return(1);
10643 }
10644
10645 //section version info
10646
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10647 {
10648 new_return(2);
10649 }
10650
10651
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10652 {
10653 new_return(3);
10654 }
10655
10656
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10657 {
10658 18 fake_pack_writing=(writecycle==0);
10659
10660 //section size
10661
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10662 {
10663 new_return(4);
10664 }
10665
10666 18 writesize=0;
10667
10668 //finally... section data
10669 18 tiles_used=count_tiles(newtilebuf)-start_tile;
10670
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 tiles_used=zc_min(tiles_used, max_tiles);
10671
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 tiles_used=zc_min(tiles_used, NEWMAXTILES);
10672
10673
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(tiles_used,f))
10674 {
10675 new_return(5);
10676 }
10677
10678
2/2
✓ Branch 0 taken 696384 times.
✓ Branch 1 taken 18 times.
696402 for(int32_t i=0; i<tiles_used; ++i)
10679 {
10680
2/2
✓ Branch 0 taken 365770 times.
✓ Branch 1 taken 330614 times.
696384 if(isblanktile(newtilebuf, start_tile+i))
10681 {
10682
1/2
✓ Branch 0 taken 365770 times.
✗ Branch 1 not taken.
365770 if(!p_putc(0,f))
10683 new_return(8);
10684 365770 }
10685 else
10686 {
10687 330614 int format = newtilebuf[start_tile+i].format;
10688
1/2
✓ Branch 0 taken 330614 times.
✗ Branch 1 not taken.
330614 if(!p_putc(format,f))
10689 {
10690 new_return(6);
10691 }
10692
10693
2/2
✓ Branch 0 taken 327742 times.
✓ Branch 1 taken 2872 times.
330614 if (format == tf4Bit)
10694 {
10695 byte temp_tile[128];
10696 327742 byte *di = temp_tile;
10697 327742 byte *src = newtilebuf[start_tile+i].data;
10698
2/2
✓ Branch 0 taken 41950976 times.
✓ Branch 1 taken 327742 times.
42278718 for (int32_t si=0; si<256; si+=2)
10699 {
10700 41950976 *di = (src[si]&15) + ((src[si+1]&15) << 4);
10701 41950976 ++di;
10702 41950976 }
10703
1/2
✓ Branch 0 taken 327742 times.
✗ Branch 1 not taken.
327742 if (!pfwrite(temp_tile,128,f))
10704 {
10705 new_return(7);
10706 }
10707 327742 }
10708
1/2
✓ Branch 0 taken 2872 times.
✗ Branch 1 not taken.
2872 else if (!pfwrite(newtilebuf[start_tile+i].data,tilesize(format),f))
10709 {
10710 new_return(7);
10711 }
10712 }
10713 696384 }
10714
10715
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10716 {
10717 9 section_size=writesize;
10718 9 }
10719 18 }
10720
10721
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10722 {
10723 char ebuf[80];
10724 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10725 jwin_alert("Error: writetiles()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10726 }
10727
10728 9 new_return(0);
10729 }
10730
10731 /* MIDI Format
10732 section_id LONG
10733 section_version WORD
10734 section_cversion WORD
10735 section_size LONG
10736 midi_flags 32 Byte ? BITFIELD[252]
10737
10738 [
10739 title 36
10740 start 4
10741 loop_start 4
10742 loop_end 4
10743 loop 2
10744 volume 2
10745 midi *
10746 ]
10747
10748 */
10749
10750 9 int32_t writemidis(PACKFILE *f)
10751 {
10752 9 dword section_id=ID_MIDIS;
10753 9 dword section_version=V_MIDIS;
10754 9 dword section_size = 0;
10755
10756 //section id
10757
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10758 {
10759 new_return(1);
10760 }
10761
10762 //section version info
10763
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10764 {
10765 new_return(2);
10766 }
10767
10768
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10769 {
10770 new_return(3);
10771 }
10772
10773
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10774 {
10775 18 fake_pack_writing=(writecycle==0);
10776
10777 //section size
10778
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10779 {
10780 new_return(4);
10781 }
10782
10783 18 writesize=0;
10784
10785 //finally... section data
10786
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(midi_flags,sizeof(midi_flags),f))
10787 {
10788 new_return(5);
10789 }
10790
10791
2/2
✓ Branch 0 taken 4536 times.
✓ Branch 1 taken 18 times.
4554 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
10792 {
10793
2/2
✓ Branch 0 taken 4406 times.
✓ Branch 1 taken 130 times.
4536 if(get_bit(midi_flags,i))
10794 {
10795
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&customtunes[i].title,sizeof(customtunes[0].title)-1,f))
10796 {
10797 new_return(6);
10798 }
10799
10800
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].start,f))
10801 {
10802 new_return(7);
10803 }
10804
10805
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].loop_start,f))
10806 {
10807 new_return(8);
10808 }
10809
10810
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].loop_end,f))
10811 {
10812 new_return(9);
10813 }
10814
10815
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputw(customtunes[i].loop,f))
10816 {
10817 new_return(10);
10818 }
10819
10820
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputw(customtunes[i].volume,f))
10821 {
10822 new_return(11);
10823 }
10824
10825
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&customtunes[i].flags, sizeof(customtunes[i].flags),f))
10826 {
10827 new_return(12);
10828 }
10829
10830 130 byte format = MFORMAT_MIDI;
10831
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&format, sizeof(format),f))
10832 {
10833 new_return(13);
10834 }
10835
10836
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if (!write_midi(customtunes[i].data, f)) new_return(14);
10837 130 }
10838 4536 }
10839
10840
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10841 {
10842 9 section_size=writesize;
10843 9 }
10844 18 }
10845
10846
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10847 {
10848 char ebuf[80];
10849 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10850 jwin_alert("Error: writemidis()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10851 }
10852
10853 9 new_return(0);
10854 }
10855
10856 9 int32_t writecheats(PACKFILE *f, zquestheader *Header)
10857 {
10858 9 dword section_id=ID_CHEATS;
10859 9 dword section_version=V_CHEATS;
10860 9 dword section_size = 0;
10861
10862 //section id
10863
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10864 {
10865 new_return(1);
10866 }
10867
10868 //section version info
10869
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10870 {
10871 new_return(2);
10872 }
10873
10874
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10875 {
10876 new_return(3);
10877 }
10878
10879
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10880 {
10881 18 fake_pack_writing=(writecycle==0);
10882
10883 //section size
10884
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10885 {
10886 new_return(4);
10887 }
10888
10889 18 writesize=0;
10890
10891 //finally... section data
10892
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->data_flags[ZQ_CHEATS2],f))
10893 {
10894 new_return(5);
10895 }
10896
10897
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(Header->data_flags[ZQ_CHEATS2])
10898 {
10899
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zcheats.flags,f))
10900 {
10901 new_return(6);
10902 }
10903
10904
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&zcheats.codes, sizeof(zcheats.codes), f))
10905 {
10906 new_return(7);
10907 }
10908 18 }
10909
10910
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10911 {
10912 9 section_size=writesize;
10913 9 }
10914 18 }
10915
10916
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10917 {
10918 char ebuf[80];
10919 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10920 jwin_alert("Error: writecheats()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10921 }
10922
10923 9 new_return(0);
10924 }
10925
10926 9 int32_t writeguys(PACKFILE *f, zquestheader *Header)
10927 {
10928 //these are here to bypass compiler warnings about unused arguments
10929 9 Header=Header;
10930
10931 9 dword section_id=ID_GUYS;
10932 9 dword section_version=V_GUYS;
10933 9 dword section_size=0;
10934
10935 //section id
10936
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10937 {
10938 new_return(1);
10939 }
10940
10941 //section version info
10942
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10943 {
10944 new_return(2);
10945 }
10946
10947
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10948 {
10949 new_return(3);
10950 }
10951
10952
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10953 {
10954 18 fake_pack_writing=(writecycle==0);
10955
10956 //section size
10957
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10958 {
10959 new_return(4);
10960 }
10961
10962 18 writesize=0;
10963
10964 //finally... section data
10965
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=0; i<MAXGUYS; i++)
10966 {
10967
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite((char *)guy_string[i], 64, f))
10968 {
10969 new_return(5);
10970 }
10971 9216 }
10972
10973
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=0; i<MAXGUYS; i++)
10974 {
10975 9216 uint32_t flags1 = uint32_t(guysbuf[i].flags);
10976 9216 uint32_t flags2 = uint32_t(guysbuf[i].flags >> 32ULL);
10977
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(flags1, f))
10978 {
10979 new_return(6);
10980 }
10981
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(flags2, f))
10982 {
10983 new_return(7);
10984 }
10985
10986
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].tile,f))
10987 {
10988 new_return(8);
10989 }
10990
10991
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].width,f))
10992 {
10993 new_return(9);
10994 }
10995
10996
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].height,f))
10997 {
10998 new_return(10);
10999 }
11000
11001
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].s_tile,f))
11002 {
11003 new_return(11);
11004 }
11005
11006
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].s_width,f))
11007 {
11008 new_return(12);
11009 }
11010
11011
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].s_height,f))
11012 {
11013 new_return(13);
11014 }
11015
11016
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].e_tile,f))
11017 {
11018 new_return(14);
11019 }
11020
11021
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].e_width,f))
11022 {
11023 new_return(15);
11024 }
11025
11026
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].e_height,f))
11027 {
11028 new_return(16);
11029 }
11030
11031
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].hp,f))
11032 {
11033 new_return(17);
11034 }
11035
11036
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].type,f))
11037 {
11038 new_return(18);
11039 }
11040
11041
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].cset,f))
11042 {
11043 new_return(19);
11044 }
11045
11046
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].anim,f))
11047 {
11048 new_return(20);
11049 }
11050
11051
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].e_anim,f))
11052 {
11053 new_return(21);
11054 }
11055
11056
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].frate,f))
11057 {
11058 new_return(22);
11059 }
11060
11061
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].e_frate,f))
11062 {
11063 new_return(23);
11064 }
11065
11066
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].dp,f))
11067 {
11068 new_return(24);
11069 }
11070
11071
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].wdp,f))
11072 {
11073 new_return(25);
11074 }
11075
11076
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].weapon,f))
11077 {
11078 new_return(26);
11079 }
11080
11081
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].rate,f))
11082 {
11083 new_return(27);
11084 }
11085
11086
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].hrate,f))
11087 {
11088 new_return(28);
11089 }
11090
11091
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].step,f))
11092 {
11093 new_return(29);
11094 }
11095
11096
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].homing,f))
11097 {
11098 new_return(30);
11099 }
11100
11101
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].grumble,f))
11102 {
11103 new_return(31);
11104 }
11105
11106
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].item_set,f))
11107 {
11108 new_return(32);
11109 }
11110
11111
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[0], f))
11112 {
11113 new_return(33);
11114 }
11115
11116
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[1],f))
11117 {
11118 new_return(34);
11119 }
11120
11121
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[2],f))
11122 {
11123 new_return(35);
11124 }
11125
11126
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[3],f))
11127 {
11128 new_return(36);
11129 }
11130
11131
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[4],f))
11132 {
11133 new_return(37);
11134 }
11135
11136
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[5],f))
11137 {
11138 new_return(38);
11139 }
11140
11141
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[6],f))
11142 {
11143 new_return(39);
11144 }
11145
11146
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[7],f))
11147 {
11148 new_return(40);
11149 }
11150
11151
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[8],f))
11152 {
11153 new_return(41);
11154 }
11155
11156
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[9],f))
11157 {
11158 new_return(42);
11159 }
11160
11161
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].bgsfx,f))
11162 {
11163 new_return(43);
11164 }
11165
11166
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].bosspal,f))
11167 {
11168 new_return(44);
11169 }
11170
11171
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].extend,f))
11172 {
11173 new_return(45);
11174 }
11175
11176
2/2
✓ Branch 0 taken 175104 times.
✓ Branch 1 taken 9216 times.
184320 for(int32_t j=0; j < edefLAST; j++)
11177 {
11178
1/2
✓ Branch 0 taken 175104 times.
✗ Branch 1 not taken.
175104 if(!p_putc(guysbuf[i].defense[j],f))
11179 {
11180 new_return(46);
11181 }
11182 175104 }
11183
11184
5/6
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6144 times.
✓ Branch 3 taken 3072 times.
✓ Branch 4 taken 2048 times.
✓ Branch 5 taken 4096 times.
9216 if ( FFCore.getQuestHeaderInfo(vZelda) < 0x250 || (( FFCore.getQuestHeaderInfo(vZelda) == 0x250 ) && FFCore.getQuestHeaderInfo(vBuild) < 32 ) )
11185 {
11186 //If no user-set hit sound was in place, and the quest was made in a version before 2.53.0 Gamma 2:
11187
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2048 times.
2048 if ( guysbuf[i].hitsfx == 0 ) guysbuf[i].hitsfx = WAV_EHIT; //Fix quests using the wrong hit sound when loading this.
11188 //Force SFX_HIT here.
11189
11190 2048 }
11191
11192
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].hitsfx,f))
11193 {
11194 new_return(47);
11195 }
11196
11197
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].deadsfx,f))
11198 {
11199 new_return(48);
11200 }
11201
11202
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[10],f))
11203 {
11204 new_return(49);
11205 }
11206
11207
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[11],f))
11208 {
11209 new_return(50);
11210 }
11211
11212 //New 2.6 defences
11213
2/2
✓ Branch 0 taken 202752 times.
✓ Branch 1 taken 9216 times.
211968 for(int32_t j=edefLAST; j < edefLAST255; j++)
11214 {
11215
1/2
✓ Branch 0 taken 202752 times.
✗ Branch 1 not taken.
202752 if(!p_putc(guysbuf[i].defense[j],f))
11216 {
11217 new_return(51);
11218 }
11219 202752 }
11220
11221 //tilewidth, tileheight, hitwidth, hitheight, hitzheight, hitxofs, hityofs, hitzofs
11222
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].txsz,f))
11223 {
11224 new_return(52);
11225 }
11226
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].tysz,f))
11227 {
11228 new_return(53);
11229 }
11230
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hxsz,f))
11231 {
11232 new_return(54);
11233 }
11234
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hysz,f))
11235 {
11236 new_return(55);
11237 }
11238
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hzsz,f))
11239 {
11240 new_return(56);
11241 }
11242 // These are not fixed types, but ints, so they are safe to use here.
11243
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hxofs,f))
11244 {
11245 new_return(57);
11246 }
11247
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hyofs,f))
11248 {
11249 new_return(58);
11250 }
11251
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].xofs,f))
11252 {
11253 new_return(59);
11254 }
11255
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].yofs,f))
11256 {
11257 new_return(60);
11258 }
11259
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].zofs,f))
11260 {
11261 new_return(61);
11262 }
11263
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].wpnsprite,f))
11264 {
11265 new_return(62);
11266 }
11267
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].SIZEflags,f))
11268 {
11269 new_return(63);
11270 }
11271
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozentile,f))
11272 {
11273 new_return(64);
11274 }
11275
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozencset,f))
11276 {
11277 new_return(65);
11278 }
11279
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozenclock,f))
11280 {
11281 new_return(66);
11282 }
11283
11284
2/2
✓ Branch 0 taken 92160 times.
✓ Branch 1 taken 9216 times.
101376 for ( int32_t q = 0; q < 10; q++ )
11285 {
11286
1/2
✓ Branch 0 taken 92160 times.
✗ Branch 1 not taken.
92160 if(!p_iputw(guysbuf[i].frozenmisc[q],f))
11287 {
11288 new_return(67);
11289 }
11290 92160 }
11291
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].firesfx,f))
11292 {
11293 new_return(68);
11294 }
11295 //misc 16->31
11296
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[15],f))
11297 {
11298 new_return(69);
11299 }
11300
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[16],f))
11301 {
11302 new_return(70);
11303 }
11304
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[17],f))
11305 {
11306 new_return(71);
11307 }
11308
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[18],f))
11309 {
11310 new_return(72);
11311 }
11312
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[19],f))
11313 {
11314 new_return(73);
11315 }
11316
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[20],f))
11317 {
11318 new_return(74);
11319 }
11320
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[21],f))
11321 {
11322 new_return(75);
11323 }
11324
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[22],f))
11325 {
11326 new_return(76);
11327 }
11328
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[23],f))
11329 {
11330 new_return(77);
11331 }
11332
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[24],f))
11333 {
11334 new_return(78);
11335 }
11336
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[25],f))
11337 {
11338 new_return(79);
11339 }
11340
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[26],f))
11341 {
11342 new_return(80);
11343 }
11344
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[27],f))
11345 {
11346 new_return(81);
11347 }
11348
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[28],f))
11349 {
11350 new_return(82);
11351 }
11352
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[29],f))
11353 {
11354 new_return(83);
11355 }
11356
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[30],f))
11357 {
11358 new_return(84);
11359 }
11360
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[31],f))
11361 {
11362 new_return(85);
11363 }
11364
2/2
✓ Branch 0 taken 294912 times.
✓ Branch 1 taken 9216 times.
304128 for ( int32_t q = 0; q < 32; q++ )
11365 {
11366
1/2
✓ Branch 0 taken 294912 times.
✗ Branch 1 not taken.
294912 if(!p_iputl(guysbuf[i].movement[q],f))
11367 {
11368 new_return(86);
11369 }
11370 294912 }
11371
2/2
✓ Branch 0 taken 294912 times.
✓ Branch 1 taken 9216 times.
304128 for ( int32_t q = 0; q < 32; q++ )
11372 {
11373
1/2
✓ Branch 0 taken 294912 times.
✗ Branch 1 not taken.
294912 if(!p_iputl(guysbuf[i].new_weapon[q],f))
11374 {
11375 new_return(87);
11376 }
11377 294912 }
11378
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].script,f))
11379 {
11380 new_return(88);
11381 }
11382
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
11383 {
11384
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(guysbuf[i].initD[q],f))
11385 {
11386 new_return(89);
11387 }
11388 73728 }
11389
2/2
✓ Branch 0 taken 18432 times.
✓ Branch 1 taken 9216 times.
27648 for ( int32_t q = 0; q < 2; q++ )
11390 {
11391
1/2
✓ Branch 0 taken 18432 times.
✗ Branch 1 not taken.
18432 if(!p_iputl(0,f))
11392 {
11393 new_return(90);
11394 }
11395 18432 }
11396
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].editorflags,f))
11397 {
11398 new_return(91);
11399 }
11400 //somehow forgot these in the older builds -Z
11401
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[12],f))
11402 {
11403 new_return(92);
11404 }
11405
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[13],f))
11406 {
11407 new_return(93);
11408 }
11409
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[14],f))
11410 {
11411 new_return(94);
11412 }
11413
11414 //Enemy Editor InitD[] labels
11415
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
11416 {
11417
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for ( int32_t w = 0; w < 65; w++ )
11418 {
11419
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(guysbuf[i].initD_label[q][w],f))
11420 {
11421 new_return(95);
11422 }
11423 4792320 }
11424 73728 }
11425
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].moveflags,f))
11426 new_return(99);
11427
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_shadow,f))
11428 new_return(100);
11429
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_death,f))
11430 new_return(101);
11431
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_spawn,f))
11432 new_return(102);
11433
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_putc(guysbuf[i].specialsfx, f))
11434 new_return(103);
11435
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9216 times.
9216 if(auto ret = write_weap_data(guysbuf[i].weap_data, f))
11436 return ret;
11437 9216 }
11438
11439
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
11440 {
11441 9 section_size=writesize;
11442 9 }
11443 18 }
11444
11445
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
11446 {
11447 char ebuf[80];
11448 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
11449 jwin_alert("Error: writeguys()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
11450 }
11451
11452 9 new_return(0);
11453 9 }
11454
11455 9 int32_t writeherosprites(PACKFILE *f, zquestheader *Header)
11456 {
11457 //these are here to bypass compiler warnings about unused arguments
11458 9 Header=Header;
11459
11460 9 dword section_id=ID_HEROSPRITES;
11461 9 dword section_version=V_HEROSPRITES;
11462 9 dword section_size=0;
11463
11464 //section id
11465
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
11466 {
11467 new_return(1);
11468 }
11469
11470 //section version info
11471
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
11472 {
11473 new_return(2);
11474 }
11475
11476
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
11477 {
11478 new_return(3);
11479 }
11480
11481
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11482 {
11483 18 fake_pack_writing=(writecycle==0);
11484
11485 //section size
11486
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
11487 {
11488 new_return(4);
11489 }
11490
11491 18 writesize=0;
11492
11493 //finally... section data
11494
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11495 {
11496
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(walkspr[i][spr_tile],f))
11497 {
11498 new_return(5);
11499 }
11500
11501
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)walkspr[i][spr_flip],f))
11502 {
11503 new_return(5);
11504 }
11505
11506
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)walkspr[i][spr_extend],f))
11507 {
11508 new_return(5);
11509 }
11510 72 }
11511
11512
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11513 {
11514
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stabspr[i][spr_tile],f))
11515 {
11516 new_return(6);
11517 }
11518
11519
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stabspr[i][spr_flip],f))
11520 {
11521 new_return(6);
11522 }
11523
11524
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stabspr[i][spr_extend],f))
11525 {
11526 new_return(6);
11527 }
11528 72 }
11529
11530
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11531 {
11532
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slashspr[i][spr_tile],f))
11533 {
11534 new_return(7);
11535 }
11536
11537
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashspr[i][spr_flip],f))
11538 {
11539 new_return(7);
11540 }
11541
11542
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashspr[i][spr_extend],f))
11543 {
11544 new_return(7);
11545 }
11546 72 }
11547
11548
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11549 {
11550
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(floatspr[i][spr_tile],f))
11551 {
11552 new_return(8);
11553 }
11554
11555
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)floatspr[i][spr_flip],f))
11556 {
11557 new_return(8);
11558 }
11559
11560
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)floatspr[i][spr_extend],f))
11561 {
11562 new_return(8);
11563 }
11564 72 }
11565
11566
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11567 {
11568
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(swimspr[i][spr_tile],f))
11569 {
11570 new_return(8);
11571 }
11572
11573
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)swimspr[i][spr_flip],f))
11574 {
11575 new_return(8);
11576 }
11577
11578
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)swimspr[i][spr_extend],f))
11579 {
11580 new_return(8);
11581 }
11582 72 }
11583
11584
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11585 {
11586
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(divespr[i][spr_tile],f))
11587 {
11588 new_return(9);
11589 }
11590
11591
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)divespr[i][spr_flip],f))
11592 {
11593 new_return(9);
11594 }
11595
11596
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)divespr[i][spr_extend],f))
11597 {
11598 new_return(9);
11599 }
11600 72 }
11601
11602
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11603 {
11604
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(poundspr[i][spr_tile],f))
11605 {
11606 new_return(10);
11607 }
11608
11609
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)poundspr[i][spr_flip],f))
11610 {
11611 new_return(10);
11612 }
11613
11614
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)poundspr[i][spr_extend],f))
11615 {
11616 new_return(10);
11617 }
11618 72 }
11619
11620
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(castingspr[spr_tile],f))
11621 {
11622 new_return(11);
11623 }
11624
11625
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)castingspr[spr_flip],f))
11626 {
11627 new_return(11);
11628 }
11629
11630
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)castingspr[spr_extend],f))
11631 {
11632 new_return(11);
11633 }
11634
11635
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 18 times.
54 for(int32_t i=0; i<2; i++)
11636 {
11637
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 36 times.
144 for(int32_t j=0; j<spr_holdmax; j++)
11638 {
11639
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 if(!p_iputl(holdspr[i][j][spr_tile],f))
11640 {
11641 new_return(12);
11642 }
11643
11644
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 if(!p_putc((byte)holdspr[i][j][spr_flip],f))
11645 {
11646 new_return(12);
11647 }
11648
11649
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 if(!p_putc((byte)holdspr[i][j][spr_extend],f))
11650 {
11651 new_return(12);
11652 }
11653 108 }
11654 36 }
11655
11656
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11657 {
11658
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(jumpspr[i][spr_tile],f))
11659 {
11660 new_return(13);
11661 }
11662
11663
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)jumpspr[i][spr_flip],f))
11664 {
11665 new_return(13);
11666 }
11667
11668
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)jumpspr[i][spr_extend],f))
11669 {
11670 new_return(13);
11671 }
11672 72 }
11673
11674
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11675 {
11676
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(chargespr[i][spr_tile],f))
11677 {
11678 new_return(13);
11679 }
11680
11681
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)chargespr[i][spr_flip],f))
11682 {
11683 new_return(13);
11684 }
11685
11686
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)chargespr[i][spr_extend],f))
11687 {
11688 new_return(13);
11689 }
11690 72 }
11691
11692
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)zinit.hero_swim_speed,f))
11693 {
11694 new_return(14);
11695 }
11696
11697 //{ V_HEROSPRITES >= 7
11698
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11699 {
11700
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(frozenspr[q][spr_tile],f))
11701 new_return(15);
11702
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozenspr[q][spr_flip],f))
11703 new_return(15);
11704
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozenspr[q][spr_extend],f))
11705 new_return(15);
11706 72 }
11707
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11708 {
11709
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(frozen_waterspr[q][spr_tile],f))
11710 new_return(15);
11711
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozen_waterspr[q][spr_flip],f))
11712 new_return(15);
11713
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozen_waterspr[q][spr_extend],f))
11714 new_return(15);
11715 72 }
11716
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11717 {
11718
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(onfirespr[q][spr_tile],f))
11719 new_return(15);
11720
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfirespr[q][spr_flip],f))
11721 new_return(15);
11722
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfirespr[q][spr_extend],f))
11723 new_return(15);
11724 72 }
11725
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11726 {
11727
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(onfire_waterspr[q][spr_tile],f))
11728 new_return(15);
11729
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfire_waterspr[q][spr_flip],f))
11730 new_return(15);
11731
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfire_waterspr[q][spr_extend],f))
11732 new_return(15);
11733 72 }
11734
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11735 {
11736
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(diggingspr[q][spr_tile],f))
11737 new_return(15);
11738
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)diggingspr[q][spr_flip],f))
11739 new_return(15);
11740
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)diggingspr[q][spr_extend],f))
11741 new_return(15);
11742 72 }
11743
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11744 {
11745
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(usingrodspr[q][spr_tile],f))
11746 new_return(15);
11747
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingrodspr[q][spr_flip],f))
11748 new_return(15);
11749
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingrodspr[q][spr_extend],f))
11750 new_return(15);
11751 72 }
11752
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11753 {
11754
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(usingcanespr[q][spr_tile],f))
11755 new_return(15);
11756
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingcanespr[q][spr_flip],f))
11757 new_return(15);
11758
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingcanespr[q][spr_extend],f))
11759 new_return(15);
11760 72 }
11761
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11762 {
11763
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(pushingspr[q][spr_tile],f))
11764 new_return(15);
11765
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pushingspr[q][spr_flip],f))
11766 new_return(15);
11767
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pushingspr[q][spr_extend],f))
11768 new_return(15);
11769 72 }
11770
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11771 {
11772
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(liftingspr[q][spr_tile],f))
11773 new_return(15);
11774
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_flip],f))
11775 new_return(15);
11776
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_extend],f))
11777 new_return(15);
11778
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_frames],f))
11779 new_return(15);
11780 72 }
11781
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11782 {
11783
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(liftingwalkspr[q][spr_tile],f))
11784 new_return(15);
11785
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingwalkspr[q][spr_flip],f))
11786 new_return(15);
11787
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingwalkspr[q][spr_extend],f))
11788 new_return(15);
11789 72 }
11790
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11791 {
11792
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stunnedspr[q][spr_tile],f))
11793 new_return(15);
11794
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunnedspr[q][spr_flip],f))
11795 new_return(15);
11796
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunnedspr[q][spr_extend],f))
11797 new_return(15);
11798 72 }
11799
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11800 {
11801
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stunned_waterspr[q][spr_tile],f))
11802 new_return(15);
11803
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunned_waterspr[q][spr_flip],f))
11804 new_return(15);
11805
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunned_waterspr[q][spr_extend],f))
11806 new_return(15);
11807 72 }
11808
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11809 {
11810
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(drowningspr[q][spr_tile],f))
11811 new_return(15);
11812
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowningspr[q][spr_flip],f))
11813 new_return(15);
11814
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowningspr[q][spr_extend],f))
11815 new_return(15);
11816 72 }
11817
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11818 {
11819
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(drowning_lavaspr[q][spr_tile],f))
11820 new_return(15);
11821
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowning_lavaspr[q][spr_flip],f))
11822 new_return(15);
11823
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowning_lavaspr[q][spr_extend],f))
11824 new_return(15);
11825 72 }
11826
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11827 {
11828
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(fallingspr[q][spr_tile],f))
11829 new_return(15);
11830
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)fallingspr[q][spr_flip],f))
11831 new_return(15);
11832
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)fallingspr[q][spr_extend],f))
11833 new_return(15);
11834 72 }
11835
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11836 {
11837
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(shockedspr[q][spr_tile],f))
11838 new_return(15);
11839
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shockedspr[q][spr_flip],f))
11840 new_return(15);
11841
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shockedspr[q][spr_extend],f))
11842 new_return(15);
11843 72 }
11844
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11845 {
11846
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(shocked_waterspr[q][spr_tile],f))
11847 new_return(15);
11848
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shocked_waterspr[q][spr_flip],f))
11849 new_return(15);
11850
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shocked_waterspr[q][spr_extend],f))
11851 new_return(15);
11852 72 }
11853
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11854 {
11855
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(pullswordspr[q][spr_tile],f))
11856 new_return(15);
11857
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pullswordspr[q][spr_flip],f))
11858 new_return(15);
11859
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pullswordspr[q][spr_extend],f))
11860 new_return(15);
11861 72 }
11862
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11863 {
11864
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(readingspr[q][spr_tile],f))
11865 new_return(15);
11866
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)readingspr[q][spr_flip],f))
11867 new_return(15);
11868
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)readingspr[q][spr_extend],f))
11869 new_return(15);
11870 72 }
11871
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11872 {
11873
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slash180spr[q][spr_tile],f))
11874 new_return(15);
11875
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slash180spr[q][spr_flip],f))
11876 new_return(15);
11877
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slash180spr[q][spr_extend],f))
11878 new_return(15);
11879 72 }
11880
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11881 {
11882
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slashZ4spr[q][spr_tile],f))
11883 new_return(15);
11884
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashZ4spr[q][spr_flip],f))
11885 new_return(15);
11886
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashZ4spr[q][spr_extend],f))
11887 new_return(15);
11888 72 }
11889
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11890 {
11891
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(dashspr[q][spr_tile],f))
11892 new_return(15);
11893
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)dashspr[q][spr_flip],f))
11894 new_return(15);
11895
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)dashspr[q][spr_extend],f))
11896 new_return(15);
11897 72 }
11898
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11899 {
11900
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(bonkspr[q][spr_tile],f))
11901 new_return(15);
11902
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)bonkspr[q][spr_flip],f))
11903 new_return(15);
11904
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)bonkspr[q][spr_extend],f))
11905 new_return(15);
11906 72 }
11907
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 18 times.
72 for(int32_t q = 0; q < 3; ++q) //Not directions; number of medallion sprs
11908 {
11909
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_iputl(medallionsprs[q][spr_tile],f))
11910 new_return(15);
11911
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)medallionsprs[q][spr_flip],f))
11912 new_return(15);
11913
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)medallionsprs[q][spr_extend],f))
11914 new_return(15);
11915 54 }
11916
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11917 {
11918
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimspr[q][spr_tile],f))
11919 new_return(16);
11920
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimspr[q][spr_flip],f))
11921 new_return(16);
11922
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimspr[q][spr_extend],f))
11923 new_return(16);
11924 72 }
11925
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11926 {
11927
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimslashspr[q][spr_tile],f))
11928 new_return(17);
11929
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimslashspr[q][spr_flip],f))
11930 new_return(17);
11931
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimslashspr[q][spr_extend],f))
11932 new_return(17);
11933 72 }
11934
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11935 {
11936
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimstabspr[q][spr_tile],f))
11937 new_return(17);
11938
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimstabspr[q][spr_flip],f))
11939 new_return(17);
11940
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimstabspr[q][spr_extend],f))
11941 new_return(17);
11942 72 }
11943
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11944 {
11945
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimpoundspr[q][spr_tile],f))
11946 new_return(17);
11947
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimpoundspr[q][spr_flip],f))
11948 new_return(17);
11949
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimpoundspr[q][spr_extend],f))
11950 new_return(17);
11951 72 }
11952
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11953 {
11954
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimchargespr[q][spr_tile],f))
11955 new_return(18);
11956
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimchargespr[q][spr_flip],f))
11957 new_return(18);
11958
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimchargespr[q][spr_extend],f))
11959 new_return(18);
11960 72 }
11961
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11962 {
11963
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(hammeroffsets[q],f))
11964 new_return(19);
11965 72 }
11966
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 18 times.
72 for(int32_t q = 0; q < 3; ++q)
11967 {
11968
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_iputl(sideswimholdspr[q][spr_tile],f))
11969 new_return(20);
11970
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)sideswimholdspr[q][spr_flip],f))
11971 new_return(20);
11972
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)sideswimholdspr[q][spr_extend],f))
11973 new_return(20);
11974 54 }
11975
11976
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(sideswimcastingspr[spr_tile],f))
11977 {
11978 new_return(21);
11979 }
11980
11981
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)sideswimcastingspr[spr_flip],f))
11982 {
11983 new_return(21);
11984 }
11985
11986
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)sideswimcastingspr[spr_extend],f))
11987 {
11988 new_return(21);
11989 }
11990
11991
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11992 {
11993
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sidedrowningspr[q][spr_tile],f))
11994 new_return(22);
11995
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sidedrowningspr[q][spr_flip],f))
11996 new_return(22);
11997
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sidedrowningspr[q][spr_extend],f))
11998 new_return(22);
11999 72 }
12000
12001
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
12002 {
12003
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(revslashspr[i][spr_tile],f))
12004 {
12005 new_return(23);
12006 }
12007
12008
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)revslashspr[i][spr_flip],f))
12009 {
12010 new_return(23);
12011 }
12012
12013
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)revslashspr[i][spr_extend],f))
12014 {
12015 new_return(23);
12016 }
12017 72 }
12018
12019
12020
2/2
✓ Branch 0 taken 2628 times.
✓ Branch 1 taken 18 times.
2646 for (int32_t q = 0; q < wMax; q++) // Hero defense values
12021 {
12022
1/2
✓ Branch 0 taken 2628 times.
✗ Branch 1 not taken.
2628 if (!p_putc(hero_defenses[q], f))
12023 new_return(15);
12024 2628 }
12025 //}
12026
12027
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
12028 {
12029 9 section_size=writesize;
12030 9 }
12031 18 }
12032
12033 //More data will come here
12034
12035
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
12036 {
12037 char ebuf[80];
12038 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12039 jwin_alert("Error: writeherosprites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12040 }
12041
12042 9 new_return(0);
12043 }
12044
12045 9 int32_t writesubscreens(PACKFILE *f, zquestheader *Header)
12046 {
12047 9 dword section_id=ID_SUBSCREEN;
12048 9 dword section_version=V_SUBSCREEN;
12049 9 dword section_size=0;
12050
12051 //section id
12052
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
12053 {
12054 new_return(1);
12055 }
12056
12057 //section version info
12058
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
12059 {
12060 new_return(2);
12061 }
12062
12063
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
12064 {
12065 new_return(3);
12066 }
12067
12068
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12069 {
12070 18 fake_pack_writing=(writecycle==0);
12071
12072 //section size
12073
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
12074 {
12075 new_return(4);
12076 }
12077
12078 18 writesize=0;
12079
12080 18 byte sz = subscreens_active.size();
12081
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12082 new_return(5);
12083
2/2
✓ Branch 0 taken 86 times.
✓ Branch 1 taken 18 times.
104 for(int32_t i=0; i<sz; i++)
12084 {
12085 86 int32_t ret = subscreens_active[i].write(f);
12086 86 fake_pack_writing=(writecycle==0);
12087
12088
1/2
✓ Branch 0 taken 86 times.
✗ Branch 1 not taken.
86 if(ret!=0)
12089 new_return(ret);
12090 86 }
12091
12092 18 sz = subscreens_passive.size();
12093
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12094 new_return(5);
12095
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 18 times.
82 for(int32_t i=0; i<sz; i++)
12096 {
12097 64 int32_t ret = subscreens_passive[i].write(f);
12098 64 fake_pack_writing=(writecycle==0);
12099
12100
1/2
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
64 if(ret!=0)
12101 new_return(ret);
12102 64 }
12103
12104 18 sz = subscreens_overlay.size();
12105
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12106 new_return(5);
12107
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 for(int32_t i=0; i<sz; i++)
12108 {
12109 int32_t ret = subscreens_overlay[i].write(f);
12110 fake_pack_writing=(writecycle==0);
12111
12112 if(ret!=0)
12113 new_return(ret);
12114 }
12115
12116 18 sz = subscreens_map.size();
12117
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12118 new_return(5);
12119
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 for(int32_t i=0; i<sz; i++)
12120 {
12121 int32_t ret = subscreens_map[i].write(f);
12122 fake_pack_writing=(writecycle==0);
12123
12124 if(ret!=0)
12125 new_return(ret);
12126 }
12127
12128
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
12129 {
12130 9 section_size=writesize;
12131 9 }
12132 18 }
12133
12134
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
12135 {
12136 char ebuf[80];
12137 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12138 jwin_alert("Error: writesubscreens()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12139 }
12140
12141 9 new_return(0);
12142 9 }
12143
12144 extern script_data *ffscripts[NUMSCRIPTFFC];
12145 extern script_data *itemscripts[NUMSCRIPTITEM];
12146 extern script_data *guyscripts[NUMSCRIPTGUYS];
12147 extern script_data *lwpnscripts[NUMSCRIPTWEAPONS];
12148 extern script_data *ewpnscripts[NUMSCRIPTWEAPONS];
12149 extern script_data *globalscripts[NUMSCRIPTGLOBAL];
12150 extern script_data *genericscripts[NUMSCRIPTSGENERIC];
12151 extern script_data *playerscripts[NUMSCRIPTHERO];
12152 extern script_data *screenscripts[NUMSCRIPTSCREEN];
12153 extern script_data *dmapscripts[NUMSCRIPTSDMAP];
12154 extern script_data *itemspritescripts[NUMSCRIPTSITEMSPRITE];
12155 extern script_data *comboscripts[NUMSCRIPTSCOMBODATA];
12156 extern script_data *subscreenscripts[NUMSCRIPTSSUBSCREEN];
12157
12158 9 int32_t writeffscript(PACKFILE *f, zquestheader *Header)
12159 {
12160
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
9 if (QMisc.zscript_last_compiled_version <= 26)
12161 3 return writeffscript_old(f, Header);
12162
12163 6 dword section_id = ID_FFSCRIPT;
12164 6 dword section_version = V_FFSCRIPT;
12165 6 dword section_size = 0;
12166 6 dword zasmmeta_version = METADATA_V;
12167 6 byte numscripts = 0;
12168 6 numscripts = numscripts; //to avoid unused variables warnings
12169
12170 //section id
12171
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
12172 {
12173 new_return(1);
12174 }
12175
12176 //section version info
12177
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
12178 {
12179 new_return(2);
12180 }
12181
12182
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!write_deprecated_section_cversion(section_version,f))
12183 {
12184 new_return(3);
12185 }
12186
12187
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(zasmmeta_version,f))
12188 {
12189 new_return(4);
12190 }
12191
12192
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12193 {
12194 12 fake_pack_writing=(writecycle==0);
12195
12196 //section size
12197
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
12198 {
12199 new_return(5);
12200 }
12201
12202 12 writesize=0;
12203
12204 12 write_quest_zasm(f);
12205
12206
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
12207 {
12208 6144 int32_t ret = write_one_ffscript(f, Header, i, ffscripts[i]);
12209
12210
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12211 {
12212 new_return(ret);
12213 }
12214 6144 }
12215
12216
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
12217 {
12218 3072 int32_t ret = write_one_ffscript(f, Header, i, itemscripts[i]);
12219
12220
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12221 {
12222 new_return(ret);
12223 }
12224 3072 }
12225
12226
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
12227 {
12228 3072 int32_t ret = write_one_ffscript(f, Header, i, guyscripts[i]);
12229
12230
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12231 {
12232 new_return(ret);
12233 }
12234 3072 }
12235
12236
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 script_data *fake = new script_data(ScriptType::None, 0);
12237
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12238 {
12239 3072 int32_t ret = write_one_ffscript(f, Header, i, fake);
12240
12241
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12242 {
12243 new_return(ret);
12244 }
12245 3072 }
12246
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 delete fake;
12247
12248
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
12249 {
12250 3072 int32_t ret = write_one_ffscript(f, Header, i, screenscripts[i]);
12251
12252
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12253 {
12254 new_return(ret);
12255 }
12256 3072 }
12257
12258
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
12259 {
12260 96 int32_t ret = write_one_ffscript(f, Header, i, globalscripts[i]);
12261
12262
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(ret!=0)
12263 {
12264 new_return(ret);
12265 }
12266 96 }
12267
12268
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 12 times.
72 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
12269 {
12270 60 int32_t ret = write_one_ffscript(f, Header, i, playerscripts[i]);
12271
12272
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(ret!=0)
12273 {
12274 new_return(ret);
12275 }
12276 60 }
12277
12278
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12279 {
12280 3072 int32_t ret = write_one_ffscript(f, Header, i, lwpnscripts[i]);
12281
12282
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12283 {
12284 new_return(ret);
12285 }
12286 3072 }
12287
12288
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12289 {
12290 3072 int32_t ret = write_one_ffscript(f, Header, i, ewpnscripts[i]);
12291
12292
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12293 {
12294 new_return(ret);
12295 }
12296 3072 }
12297
12298
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
12299 {
12300 3072 int32_t ret = write_one_ffscript(f, Header, i, dmapscripts[i]);
12301
12302
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12303 {
12304 new_return(ret);
12305 }
12306 3072 }
12307
12308
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
12309 {
12310 3072 int32_t ret = write_one_ffscript(f, Header, i, itemspritescripts[i]);
12311
12312
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12313 {
12314 new_return(ret);
12315 }
12316 3072 }
12317
12318
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
12319 {
12320 6144 int32_t ret = write_one_ffscript(f, Header, i, comboscripts[i]);
12321
12322
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12323 {
12324 new_return(ret);
12325 }
12326 6144 }
12327
12328
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSGENERIC,f))
12329 {
12330 new_return(2000);
12331 }
12332
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
12333 {
12334 6144 int32_t ret = write_one_ffscript(f, Header, i, genericscripts[i]);
12335
12336
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12337 {
12338 new_return(ret);
12339 }
12340 6144 }
12341
12342
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSSUBSCREEN,f))
12343 {
12344 new_return(2001);
12345 }
12346
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
12347 {
12348 3072 int32_t ret = write_one_ffscript(f, Header, i, subscreenscripts[i]);
12349
12350
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12351 {
12352 new_return(ret);
12353 }
12354 3072 }
12355
12356
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputl((int32_t)zScript.size(), f))
12357 {
12358 new_return(2001);
12359 }
12360
12361
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!pfwrite((void *)zScript.c_str(), (int32_t)zScript.size(), f))
12362 {
12363 new_return(2002);
12364 }
12365
12366 12 word numffcbindings=0;
12367
12368
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12369 {
12370
2/2
✓ Branch 0 taken 5974 times.
✓ Branch 1 taken 158 times.
6132 if(it->second.scriptname != "")
12371 {
12372 158 numffcbindings++;
12373 158 }
12374 6132 }
12375
12376
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numffcbindings, f))
12377 {
12378 new_return(2003);
12379 }
12380
12381
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12382 {
12383
2/2
✓ Branch 0 taken 5974 times.
✓ Branch 1 taken 158 times.
6132 if(it->second.scriptname != "")
12384 {
12385
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!p_iputw(it->first,f))
12386 {
12387 new_return(2004);
12388 }
12389
12390
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12391 {
12392 new_return(2005);
12393 }
12394
12395
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12396 {
12397 new_return(2006);
12398 }
12399 158 }
12400 6132 }
12401
12402 12 word numglobalbindings=0;
12403
12404
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12405 {
12406
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 22 times.
96 if(it->second.scriptname != "")
12407 {
12408 22 numglobalbindings++;
12409 22 }
12410 96 }
12411
12412
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numglobalbindings, f))
12413 {
12414 new_return(2007);
12415 }
12416
12417
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12418 {
12419
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 22 times.
96 if(it->second.scriptname != "")
12420 {
12421
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputw(it->first,f))
12422 {
12423 new_return(2008);
12424 }
12425
12426
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12427 {
12428 new_return(2009);
12429 }
12430
12431
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12432 {
12433 new_return(2010);
12434 }
12435 22 }
12436 96 }
12437
12438 12 word numitembindings=0;
12439
12440
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12441 {
12442
2/2
✓ Branch 0 taken 3034 times.
✓ Branch 1 taken 26 times.
3060 if(it->second.scriptname != "")
12443 {
12444 26 numitembindings++;
12445 26 }
12446 3060 }
12447
12448
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitembindings, f))
12449 {
12450 new_return(2011);
12451 }
12452
12453
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12454 {
12455
2/2
✓ Branch 0 taken 3034 times.
✓ Branch 1 taken 26 times.
3060 if(it->second.scriptname != "")
12456 {
12457
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputw(it->first,f))
12458 {
12459 new_return(2012);
12460 }
12461
12462
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12463 {
12464 new_return(2013);
12465 }
12466
12467
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12468 {
12469 new_return(2014);
12470 }
12471 26 }
12472 3060 }
12473
12474 //new script types
12475 //npc scripts
12476 12 word numnpcbindings=0;
12477
12478
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12479 {
12480
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12481 {
12482 numnpcbindings++;
12483 }
12484 3060 }
12485
12486
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numnpcbindings, f))
12487 {
12488 new_return(2015);
12489 }
12490
12491
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12492 {
12493
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12494 {
12495 if(!p_iputw(it->first,f))
12496 {
12497 new_return(2016);
12498 }
12499
12500 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12501 {
12502 new_return(2017);
12503 }
12504
12505 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12506 {
12507 new_return(2018);
12508 }
12509 }
12510 3060 }
12511
12512 //lweapon
12513
12514 12 word numlwpnbindings=0;
12515
12516
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12517 {
12518
2/2
✓ Branch 0 taken 3058 times.
✓ Branch 1 taken 2 times.
3060 if(it->second.scriptname != "")
12519 {
12520 2 numlwpnbindings++;
12521 2 }
12522 3060 }
12523
12524
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numlwpnbindings, f))
12525 {
12526 new_return(2019);
12527 }
12528
12529
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12530 {
12531
2/2
✓ Branch 0 taken 3058 times.
✓ Branch 1 taken 2 times.
3060 if(it->second.scriptname != "")
12532 {
12533
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputw(it->first,f))
12534 {
12535 new_return(2020);
12536 }
12537
12538
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12539 {
12540 new_return(2021);
12541 }
12542
12543
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12544 {
12545 new_return(2022);
12546 }
12547 2 }
12548 3060 }
12549
12550 //////
12551
12552 //eweapon
12553
12554
12555 12 word numewpnbindings=0;
12556
12557
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12558 {
12559
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12560 {
12561 numewpnbindings++;
12562 }
12563 3060 }
12564
12565
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numewpnbindings, f))
12566 {
12567 new_return(2023);
12568 }
12569
12570
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12571 {
12572
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12573 {
12574 if(!p_iputw(it->first,f))
12575 {
12576 new_return(2024);
12577 }
12578
12579 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12580 {
12581 new_return(2025);
12582 }
12583
12584 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12585 {
12586 new_return(2026);
12587 }
12588 }
12589 3060 }
12590
12591 //player scripts
12592 12 word numherobindings=0;
12593
12594
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12595 {
12596
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(it->second.scriptname != "")
12597 {
12598 numherobindings++;
12599 }
12600 48 }
12601
12602
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numherobindings, f))
12603 {
12604 new_return(2027);
12605 }
12606
12607
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12608 {
12609
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(it->second.scriptname != "")
12610 {
12611 if(!p_iputw(it->first,f))
12612 {
12613 new_return(2028);
12614 }
12615
12616 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12617 {
12618 new_return(2029);
12619 }
12620
12621 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12622 {
12623 new_return(2030);
12624 }
12625 }
12626 48 }
12627
12628 //dmap scripts
12629 12 word numdmapbindings=0;
12630
12631
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12632 {
12633
2/2
✓ Branch 0 taken 3050 times.
✓ Branch 1 taken 10 times.
3060 if(it->second.scriptname != "")
12634 {
12635 10 numdmapbindings++;
12636 10 }
12637 3060 }
12638
12639
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numdmapbindings, f))
12640 {
12641 new_return(2031);
12642 }
12643
12644
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12645 {
12646
2/2
✓ Branch 0 taken 3050 times.
✓ Branch 1 taken 10 times.
3060 if(it->second.scriptname != "")
12647 {
12648
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_iputw(it->first,f))
12649 {
12650 new_return(2032);
12651 }
12652
12653
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12654 {
12655 new_return(2033);
12656 }
12657
12658
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12659 {
12660 new_return(2034);
12661 }
12662 10 }
12663 3060 }
12664
12665 //screen scripts
12666 12 word numscreenbindings=0;
12667
12668
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12669 {
12670
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12671 {
12672 4 numscreenbindings++;
12673 4 }
12674 3060 }
12675
12676
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numscreenbindings, f))
12677 {
12678 new_return(2035);
12679 }
12680
12681
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12682 {
12683
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12684 {
12685
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputw(it->first,f))
12686 {
12687 new_return(2036);
12688 }
12689
12690
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12691 {
12692 new_return(2037);
12693 }
12694
12695
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12696 {
12697 new_return(2038);
12698 }
12699 4 }
12700 3060 }
12701 //item sprite scripts
12702 12 word numitemspritebindings=0;
12703
12704
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12705 {
12706
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12707 {
12708 numitemspritebindings++;
12709 }
12710 3060 }
12711
12712
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitemspritebindings, f))
12713 {
12714 new_return(2039);
12715 }
12716
12717
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12718 {
12719
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12720 {
12721 if(!p_iputw(it->first,f))
12722 {
12723 new_return(2040);
12724 }
12725
12726 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12727 {
12728 new_return(2041);
12729 }
12730
12731 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12732 {
12733 new_return(2042);
12734 }
12735 }
12736 3060 }
12737
12738 //combo scripts
12739 12 word numcombobindings=0;
12740
12741
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12742 {
12743
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12744 {
12745 numcombobindings++;
12746 }
12747 6132 }
12748
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numcombobindings, f))
12749 {
12750 new_return(2043);
12751 }
12752
12753
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12754 {
12755
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12756 {
12757 if(!p_iputw(it->first,f))
12758 {
12759 new_return(2044);
12760 }
12761
12762 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12763 {
12764 new_return(2045);
12765 }
12766
12767 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12768 {
12769 new_return(2046);
12770 }
12771 }
12772 6132 }
12773 //subscreen scripts
12774 12 word numgenericbindings=0;
12775
12776
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12777 {
12778
2/2
✓ Branch 0 taken 6090 times.
✓ Branch 1 taken 42 times.
6132 if(it->second.scriptname != "")
12779 {
12780 42 numgenericbindings++;
12781 42 }
12782 6132 }
12783
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numgenericbindings, f))
12784 {
12785 new_return(2043);
12786 }
12787
12788
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12789 {
12790
2/2
✓ Branch 0 taken 6090 times.
✓ Branch 1 taken 42 times.
6132 if(it->second.scriptname != "")
12791 {
12792
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 if(!p_iputw(it->first,f))
12793 {
12794 new_return(2044);
12795 }
12796
12797
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12798 {
12799 new_return(2045);
12800 }
12801
12802
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12803 {
12804 new_return(2046);
12805 }
12806 42 }
12807 6132 }
12808
12809 //generic scripts
12810 12 word numsubscreenbindings=0;
12811
12812
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
12813 {
12814
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12815 {
12816 numsubscreenbindings++;
12817 }
12818 3060 }
12819
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numsubscreenbindings, f))
12820 {
12821 new_return(2047);
12822 }
12823
12824
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
12825 {
12826
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12827 {
12828 if(!p_iputw(it->first,f))
12829 {
12830 new_return(2048);
12831 }
12832
12833 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12834 {
12835 new_return(2049);
12836 }
12837
12838 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12839 {
12840 new_return(2050);
12841 }
12842 }
12843 3060 }
12844
12845
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
12846 {
12847 6 section_size=writesize;
12848 6 }
12849 12 }
12850
12851
12852
12853
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
12854 {
12855 char ebuf[80];
12856 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12857 jwin_alert("Error: writeffscript()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12858 }
12859
12860 6 new_return(0);
12861 //return 0; //this is just here to stomp the compiler from whining.
12862 //the irony is that it causes an "unreachable code" warning.
12863 9 }
12864
12865 12 int32_t write_quest_zasm(PACKFILE *f)
12866 {
12867 extern std::vector<std::shared_ptr<zasm_script>> zasm_scripts;
12868
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (zasm_scripts.empty())
12869 {
12870 if(!p_iputl(0,f))
12871 new_return(1);
12872
12873 return 0;
12874 }
12875
12876 12 auto& zasm = zasm_scripts[0]->zasm;
12877 12 size_t num_commands = zasm.size();
12878
12879
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(num_commands,f))
12880 new_return(1);
12881
12882
2/2
✓ Branch 0 taken 372806 times.
✓ Branch 1 taken 12 times.
372818 for(int32_t j=0; j<num_commands; j++)
12883 {
12884 372806 auto& zas = zasm[j];
12885
12886
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 372806 times.
372806 if(zas.command==0xFFFF)
12887 continue;
12888 else
12889 {
12890
1/2
✓ Branch 0 taken 372806 times.
✗ Branch 1 not taken.
372806 if(!p_iputw(zas.command,f))
12891 new_return(2);
12892
12893
1/2
✓ Branch 0 taken 372806 times.
✗ Branch 1 not taken.
372806 if(!p_iputl(zas.arg1,f))
12894 new_return(3);
12895
12896
1/2
✓ Branch 0 taken 372806 times.
✗ Branch 1 not taken.
372806 if(!p_iputl(zas.arg2,f))
12897 new_return(4);
12898
12899
1/2
✓ Branch 0 taken 372806 times.
✗ Branch 1 not taken.
372806 if(!p_iputl(zas.arg3,f))
12900 new_return(5);
12901
12902 372806 uint32_t sz = 0;
12903
2/2
✓ Branch 0 taken 371822 times.
✓ Branch 1 taken 984 times.
372806 if(zas.strptr)
12904 984 sz = zas.strptr->size();
12905
1/2
✓ Branch 0 taken 372806 times.
✗ Branch 1 not taken.
372806 if(!p_iputl(sz,f))
12906 new_return(6);
12907
2/2
✓ Branch 0 taken 371834 times.
✓ Branch 1 taken 972 times.
372806 if(sz)
12908 {
12909 972 auto& str = *zas.strptr;
12910
2/2
✓ Branch 0 taken 20822 times.
✓ Branch 1 taken 972 times.
21794 for(size_t q = 0; q < sz; ++q)
12911 {
12912
1/2
✓ Branch 0 taken 20822 times.
✗ Branch 1 not taken.
20822 if(!p_putc(str[q],f))
12913 new_return(7);
12914 20822 }
12915 972 }
12916 372806 sz = 0;
12917
2/2
✓ Branch 0 taken 372598 times.
✓ Branch 1 taken 208 times.
372806 if(zas.vecptr)
12918 208 sz = zas.vecptr->size();
12919
1/2
✓ Branch 0 taken 372806 times.
✗ Branch 1 not taken.
372806 if(!p_iputl(sz,f))
12920 new_return(8);
12921
2/2
✓ Branch 0 taken 372598 times.
✓ Branch 1 taken 208 times.
372806 if(sz) //vector found
12922 {
12923 208 auto& vec = *zas.vecptr;
12924
2/2
✓ Branch 0 taken 1302 times.
✓ Branch 1 taken 208 times.
1510 for(size_t q = 0; q < sz; ++q)
12925 {
12926
1/2
✓ Branch 0 taken 1302 times.
✗ Branch 1 not taken.
1302 if(!p_iputl(vec[q],f))
12927 new_return(9);
12928 1302 }
12929 208 }
12930 }
12931 372806 }
12932 12 return 0;
12933 12 }
12934
12935 46236 int32_t write_one_ffscript(PACKFILE *f, zquestheader *, int32_t, script_data *script)
12936 {
12937
2/2
✓ Branch 0 taken 45986 times.
✓ Branch 1 taken 250 times.
46236 if (!script->valid())
12938 {
12939
1/2
✓ Branch 0 taken 45986 times.
✗ Branch 1 not taken.
45986 if (!p_putc(0, f))
12940 new_return(-1);
12941 45986 return 0;
12942 }
12943
12944
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if (!p_putc(1, f))
12945 new_return(-1);
12946
12947 250 zasm_meta const& tmeta = script->meta;
12948
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_iputw(tmeta.zasm_v,f))
12949 new_return(1);
12950
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_iputw(tmeta.meta_v,f))
12951 new_return(2);
12952
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_iputw(tmeta.ffscript_v,f))
12953 new_return(3);
12954
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_putc((int)tmeta.script_type,f))
12955 new_return(4);
12956
12957
2/2
✓ Branch 0 taken 2000 times.
✓ Branch 1 taken 250 times.
2250 for(int32_t q = 0; q < 8; ++q)
12958 {
12959
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putcstr(tmeta.run_idens[q],f))
12960 new_return(5);
12961 2000 }
12962
12963
2/2
✓ Branch 0 taken 2000 times.
✓ Branch 1 taken 250 times.
2250 for(int32_t q = 0; q < 8; ++q)
12964
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putc(tmeta.run_types[q],f))
12965 new_return(6);
12966
12967
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_putc(tmeta.flags,f))
12968 new_return(7);
12969
12970
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_iputw(tmeta.compiler_v1,f))
12971 new_return(8);
12972
12973
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_iputw(tmeta.compiler_v2,f))
12974 new_return(9);
12975
12976
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_iputw(tmeta.compiler_v3,f))
12977 new_return(10);
12978
12979
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_iputw(tmeta.compiler_v4,f))
12980 new_return(11);
12981
12982
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_putcstr(tmeta.script_name,f))
12983 new_return(12);
12984
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_putcstr(tmeta.author,f))
12985 new_return(13);
12986
2/2
✓ Branch 0 taken 2500 times.
✓ Branch 1 taken 250 times.
2750 for(auto q = 0; q < 10; ++q)
12987 {
12988
1/2
✓ Branch 0 taken 2500 times.
✗ Branch 1 not taken.
2500 if(!p_putcstr(tmeta.attributes[q],f))
12989 new_return(14);
12990
1/2
✓ Branch 0 taken 2500 times.
✗ Branch 1 not taken.
2500 if(!p_putwstr(tmeta.attributes_help[q],f))
12991 new_return(15);
12992 2500 }
12993
2/2
✓ Branch 0 taken 2000 times.
✓ Branch 1 taken 250 times.
2250 for(auto q = 0; q < 8; ++q)
12994 {
12995
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putcstr(tmeta.attribytes[q],f))
12996 new_return(16);
12997
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putwstr(tmeta.attribytes_help[q],f))
12998 new_return(17);
12999 2000 }
13000
2/2
✓ Branch 0 taken 2000 times.
✓ Branch 1 taken 250 times.
2250 for(auto q = 0; q < 8; ++q)
13001 {
13002
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putcstr(tmeta.attrishorts[q],f))
13003 new_return(18);
13004
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putwstr(tmeta.attrishorts_help[q],f))
13005 new_return(19);
13006 2000 }
13007
2/2
✓ Branch 0 taken 4000 times.
✓ Branch 1 taken 250 times.
4250 for(auto q = 0; q < 16; ++q)
13008 {
13009
1/2
✓ Branch 0 taken 4000 times.
✗ Branch 1 not taken.
4000 if(!p_putcstr(tmeta.usrflags[q],f))
13010 new_return(20);
13011
1/2
✓ Branch 0 taken 4000 times.
✗ Branch 1 not taken.
4000 if(!p_putwstr(tmeta.usrflags_help[q],f))
13012 new_return(21);
13013 4000 }
13014
2/2
✓ Branch 0 taken 2000 times.
✓ Branch 1 taken 250 times.
2250 for(auto q = 0; q < 8; ++q)
13015 {
13016
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putcstr(tmeta.initd[q],f))
13017 new_return(22);
13018
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putwstr(tmeta.initd_help[q],f))
13019 new_return(23);
13020 2000 }
13021
2/2
✓ Branch 0 taken 2000 times.
✓ Branch 1 taken 250 times.
2250 for(auto q = 0; q < 8; ++q)
13022 {
13023
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putc(tmeta.initd_type[q],f))
13024 new_return(24);
13025 2000 }
13026
13027
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_iputl(script->pc, f))
13028 new_return(25);
13029
13030
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 250 times.
250 if(!p_iputl(script->end_pc, f))
13031 new_return(26);
13032
13033 250 return 0;
13034 46236 }
13035
13036
13037 3 int32_t writeffscript_old(PACKFILE *f, zquestheader *Header)
13038 {
13039 3 dword section_id = ID_FFSCRIPT;
13040 3 dword section_version = 26;
13041 3 dword section_cversion = 1;
13042 3 dword section_size = 0;
13043 3 dword zasmmeta_version = 5;
13044 3 byte numscripts = 0;
13045 3 numscripts = numscripts; //to avoid unused variables warnings
13046
13047 //section id
13048
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_mputl(section_id,f))
13049 {
13050 new_return(1);
13051 }
13052
13053 //section version info
13054
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(section_version,f))
13055 {
13056 new_return(2);
13057 }
13058
13059
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(section_cversion,f))
13060 {
13061 new_return(3);
13062 }
13063
13064
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(zasmmeta_version,f))
13065 {
13066 new_return(4);
13067 }
13068
13069
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
9 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13070 {
13071 6 fake_pack_writing=(writecycle==0);
13072
13073 //section size
13074
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputl(section_size,f))
13075 {
13076 new_return(5);
13077 }
13078
13079 6 writesize=0;
13080
13081
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
13082 {
13083 3072 int32_t ret = write_one_ffscript_old(f, Header, i, ffscripts[i]);
13084 3072 fake_pack_writing=(writecycle==0);
13085
13086
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13087 {
13088 new_return(ret);
13089 }
13090 3072 }
13091
13092
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
13093 {
13094 1536 int32_t ret = write_one_ffscript_old(f, Header, i, itemscripts[i]);
13095 1536 fake_pack_writing=(writecycle==0);
13096
13097
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13098 {
13099 new_return(ret);
13100 }
13101 1536 }
13102
13103
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
13104 {
13105 1536 int32_t ret = write_one_ffscript_old(f, Header, i, guyscripts[i]);
13106 1536 fake_pack_writing=(writecycle==0);
13107
13108
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13109 {
13110 new_return(ret);
13111 }
13112 1536 }
13113
13114
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 script_data *fake = new script_data(ScriptType::None, 0);
13115
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13116 {
13117 1536 int32_t ret = write_one_ffscript_old(f, Header, i, fake);
13118 1536 fake_pack_writing=(writecycle==0);
13119
13120
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13121 {
13122 new_return(ret);
13123 }
13124 1536 }
13125
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 delete fake;
13126
13127
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
13128 {
13129 1536 int32_t ret = write_one_ffscript_old(f, Header, i, screenscripts[i]);
13130 1536 fake_pack_writing=(writecycle==0);
13131
13132
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13133 {
13134 new_return(ret);
13135 }
13136 1536 }
13137
13138
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
13139 {
13140 48 int32_t ret = write_one_ffscript_old(f, Header, i, globalscripts[i]);
13141 48 fake_pack_writing=(writecycle==0);
13142
13143
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(ret!=0)
13144 {
13145 new_return(ret);
13146 }
13147 48 }
13148
13149
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 6 times.
36 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
13150 {
13151 30 int32_t ret = write_one_ffscript_old(f, Header, i, playerscripts[i]);
13152 30 fake_pack_writing=(writecycle==0);
13153
13154
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if(ret!=0)
13155 {
13156 new_return(ret);
13157 }
13158 30 }
13159
13160
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13161 {
13162 1536 int32_t ret = write_one_ffscript_old(f, Header, i, lwpnscripts[i]);
13163 1536 fake_pack_writing=(writecycle==0);
13164
13165
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13166 {
13167 new_return(ret);
13168 }
13169 1536 }
13170
13171
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13172 {
13173 1536 int32_t ret = write_one_ffscript_old(f, Header, i, ewpnscripts[i]);
13174 1536 fake_pack_writing=(writecycle==0);
13175
13176
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13177 {
13178 new_return(ret);
13179 }
13180 1536 }
13181
13182
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
13183 {
13184 1536 int32_t ret = write_one_ffscript_old(f, Header, i, dmapscripts[i]);
13185 1536 fake_pack_writing=(writecycle==0);
13186
13187
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13188 {
13189 new_return(ret);
13190 }
13191 1536 }
13192
13193
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
13194 {
13195 1536 int32_t ret = write_one_ffscript_old(f, Header, i, itemspritescripts[i]);
13196 1536 fake_pack_writing=(writecycle==0);
13197
13198
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13199 {
13200 new_return(ret);
13201 }
13202 1536 }
13203
13204
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
13205 {
13206 3072 int32_t ret = write_one_ffscript_old(f, Header, i, comboscripts[i]);
13207 3072 fake_pack_writing=(writecycle==0);
13208
13209
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13210 {
13211 new_return(ret);
13212 }
13213 3072 }
13214
13215
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(NUMSCRIPTSGENERIC,f))
13216 {
13217 new_return(2000);
13218 }
13219
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
13220 {
13221 3072 int32_t ret = write_one_ffscript_old(f, Header, i, genericscripts[i]);
13222 3072 fake_pack_writing=(writecycle==0);
13223
13224
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13225 {
13226 new_return(ret);
13227 }
13228 3072 }
13229
13230
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(NUMSCRIPTSSUBSCREEN,f))
13231 {
13232 new_return(2001);
13233 }
13234
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
13235 {
13236 1536 int32_t ret = write_one_ffscript_old(f, Header, i, subscreenscripts[i]);
13237 1536 fake_pack_writing=(writecycle==0);
13238
13239
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13240 {
13241 new_return(ret);
13242 }
13243 1536 }
13244
13245
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputl((int32_t)zScript.size(), f))
13246 {
13247 new_return(2001);
13248 }
13249
13250
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!pfwrite((void *)zScript.c_str(), (int32_t)zScript.size(), f))
13251 {
13252 new_return(2002);
13253 }
13254
13255 6 word numffcbindings=0;
13256
13257
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
13258 {
13259
2/2
✓ Branch 0 taken 2860 times.
✓ Branch 1 taken 206 times.
3066 if(it->second.scriptname != "")
13260 {
13261 206 numffcbindings++;
13262 206 }
13263 3066 }
13264
13265
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numffcbindings, f))
13266 {
13267 new_return(2003);
13268 }
13269
13270
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
13271 {
13272
2/2
✓ Branch 0 taken 2860 times.
✓ Branch 1 taken 206 times.
3066 if(it->second.scriptname != "")
13273 {
13274
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!p_iputw(it->first,f))
13275 {
13276 new_return(2004);
13277 }
13278
13279
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13280 {
13281 new_return(2005);
13282 }
13283
13284
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13285 {
13286 new_return(2006);
13287 }
13288 206 }
13289 3066 }
13290
13291 6 word numglobalbindings=0;
13292
13293
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
13294 {
13295
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 18 times.
48 if(it->second.scriptname != "")
13296 {
13297 18 numglobalbindings++;
13298 18 }
13299 48 }
13300
13301
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numglobalbindings, f))
13302 {
13303 new_return(2007);
13304 }
13305
13306
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
13307 {
13308
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 18 times.
48 if(it->second.scriptname != "")
13309 {
13310
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(it->first,f))
13311 {
13312 new_return(2008);
13313 }
13314
13315
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13316 {
13317 new_return(2009);
13318 }
13319
13320
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13321 {
13322 new_return(2010);
13323 }
13324 18 }
13325 48 }
13326
13327 6 word numitembindings=0;
13328
13329
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
13330 {
13331
2/2
✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 18 times.
1530 if(it->second.scriptname != "")
13332 {
13333 18 numitembindings++;
13334 18 }
13335 1530 }
13336
13337
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numitembindings, f))
13338 {
13339 new_return(2011);
13340 }
13341
13342
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
13343 {
13344
2/2
✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 18 times.
1530 if(it->second.scriptname != "")
13345 {
13346
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(it->first,f))
13347 {
13348 new_return(2012);
13349 }
13350
13351
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13352 {
13353 new_return(2013);
13354 }
13355
13356
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13357 {
13358 new_return(2014);
13359 }
13360 18 }
13361 1530 }
13362
13363 //new script types
13364 //npc scripts
13365 6 word numnpcbindings=0;
13366
13367
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
13368 {
13369
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13370 {
13371 numnpcbindings++;
13372 }
13373 1530 }
13374
13375
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numnpcbindings, f))
13376 {
13377 new_return(2015);
13378 }
13379
13380
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
13381 {
13382
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13383 {
13384 if(!p_iputw(it->first,f))
13385 {
13386 new_return(2016);
13387 }
13388
13389 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13390 {
13391 new_return(2017);
13392 }
13393
13394 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13395 {
13396 new_return(2018);
13397 }
13398 }
13399 1530 }
13400
13401 //lweapon
13402
13403 6 word numlwpnbindings=0;
13404
13405
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
13406 {
13407
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13408 {
13409 numlwpnbindings++;
13410 }
13411 1530 }
13412
13413
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numlwpnbindings, f))
13414 {
13415 new_return(2019);
13416 }
13417
13418
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
13419 {
13420
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13421 {
13422 if(!p_iputw(it->first,f))
13423 {
13424 new_return(2020);
13425 }
13426
13427 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13428 {
13429 new_return(2021);
13430 }
13431
13432 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13433 {
13434 new_return(2022);
13435 }
13436 }
13437 1530 }
13438
13439 //////
13440
13441 //eweapon
13442
13443
13444 6 word numewpnbindings=0;
13445
13446
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
13447 {
13448
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13449 {
13450 numewpnbindings++;
13451 }
13452 1530 }
13453
13454
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numewpnbindings, f))
13455 {
13456 new_return(2023);
13457 }
13458
13459
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
13460 {
13461
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13462 {
13463 if(!p_iputw(it->first,f))
13464 {
13465 new_return(2024);
13466 }
13467
13468 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13469 {
13470 new_return(2025);
13471 }
13472
13473 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13474 {
13475 new_return(2026);
13476 }
13477 }
13478 1530 }
13479
13480 //player scripts
13481 6 word numherobindings=0;
13482
13483
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
13484 {
13485
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 2 times.
24 if(it->second.scriptname != "")
13486 {
13487 2 numherobindings++;
13488 2 }
13489 24 }
13490
13491
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numherobindings, f))
13492 {
13493 new_return(2027);
13494 }
13495
13496
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
13497 {
13498
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 2 times.
24 if(it->second.scriptname != "")
13499 {
13500
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputw(it->first,f))
13501 {
13502 new_return(2028);
13503 }
13504
13505
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13506 {
13507 new_return(2029);
13508 }
13509
13510
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13511 {
13512 new_return(2030);
13513 }
13514 2 }
13515 24 }
13516
13517 //dmap scripts
13518 6 word numdmapbindings=0;
13519
13520
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
13521 {
13522
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13523 {
13524 numdmapbindings++;
13525 }
13526 1530 }
13527
13528
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numdmapbindings, f))
13529 {
13530 new_return(2031);
13531 }
13532
13533
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
13534 {
13535
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13536 {
13537 if(!p_iputw(it->first,f))
13538 {
13539 new_return(2032);
13540 }
13541
13542 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13543 {
13544 new_return(2033);
13545 }
13546
13547 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13548 {
13549 new_return(2034);
13550 }
13551 }
13552 1530 }
13553
13554 //screen scripts
13555 6 word numscreenbindings=0;
13556
13557
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
13558 {
13559
2/2
✓ Branch 0 taken 1516 times.
✓ Branch 1 taken 14 times.
1530 if(it->second.scriptname != "")
13560 {
13561 14 numscreenbindings++;
13562 14 }
13563 1530 }
13564
13565
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numscreenbindings, f))
13566 {
13567 new_return(2035);
13568 }
13569
13570
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
13571 {
13572
2/2
✓ Branch 0 taken 1516 times.
✓ Branch 1 taken 14 times.
1530 if(it->second.scriptname != "")
13573 {
13574
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!p_iputw(it->first,f))
13575 {
13576 new_return(2036);
13577 }
13578
13579
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13580 {
13581 new_return(2037);
13582 }
13583
13584
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13585 {
13586 new_return(2038);
13587 }
13588 14 }
13589 1530 }
13590 //item sprite scripts
13591 6 word numitemspritebindings=0;
13592
13593
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
13594 {
13595
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13596 {
13597 numitemspritebindings++;
13598 }
13599 1530 }
13600
13601
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numitemspritebindings, f))
13602 {
13603 new_return(2039);
13604 }
13605
13606
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
13607 {
13608
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13609 {
13610 if(!p_iputw(it->first,f))
13611 {
13612 new_return(2040);
13613 }
13614
13615 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13616 {
13617 new_return(2041);
13618 }
13619
13620 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13621 {
13622 new_return(2042);
13623 }
13624 }
13625 1530 }
13626
13627 //combo scripts
13628 6 word numcombobindings=0;
13629
13630
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
13631 {
13632
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13633 {
13634 numcombobindings++;
13635 }
13636 3066 }
13637
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numcombobindings, f))
13638 {
13639 new_return(2043);
13640 }
13641
13642
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
13643 {
13644
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13645 {
13646 if(!p_iputw(it->first,f))
13647 {
13648 new_return(2044);
13649 }
13650
13651 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13652 {
13653 new_return(2045);
13654 }
13655
13656 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13657 {
13658 new_return(2046);
13659 }
13660 }
13661 3066 }
13662 //subscreen scripts
13663 6 word numgenericbindings=0;
13664
13665
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
13666 {
13667
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13668 {
13669 numgenericbindings++;
13670 }
13671 3066 }
13672
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numgenericbindings, f))
13673 {
13674 new_return(2043);
13675 }
13676
13677
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
13678 {
13679
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13680 {
13681 if(!p_iputw(it->first,f))
13682 {
13683 new_return(2044);
13684 }
13685
13686 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13687 {
13688 new_return(2045);
13689 }
13690
13691 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13692 {
13693 new_return(2046);
13694 }
13695 }
13696 3066 }
13697
13698 //generic scripts
13699 6 word numsubscreenbindings=0;
13700
13701
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13702 {
13703
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13704 {
13705 numsubscreenbindings++;
13706 }
13707 1530 }
13708
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numsubscreenbindings, f))
13709 {
13710 new_return(2047);
13711 }
13712
13713
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13714 {
13715
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13716 {
13717 if(!p_iputw(it->first,f))
13718 {
13719 new_return(2048);
13720 }
13721
13722 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13723 {
13724 new_return(2049);
13725 }
13726
13727 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13728 {
13729 new_return(2050);
13730 }
13731 }
13732 1530 }
13733
13734
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if(writecycle==0)
13735 {
13736 3 section_size=writesize;
13737 3 }
13738 6 }
13739
13740
13741
13742
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3 if(writesize!=int32_t(section_size) && save_warn)
13743 {
13744 char ebuf[80];
13745 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13746 jwin_alert("Error: writeffscript()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13747 }
13748
13749 3 new_return(0);
13750 //return 0; //this is just here to stomp the compiler from whining.
13751 //the irony is that it causes an "unreachable code" warning.
13752 3 }
13753
13754 23118 int32_t write_one_ffscript_old(PACKFILE *f, zquestheader *Header, int32_t i, script_data *script)
13755 {
13756 //these are here to bypass compiler warnings about unused arguments
13757 23118 Header=Header;
13758 23118 i=i;
13759
13760
2/2
✓ Branch 0 taken 11830 times.
✓ Branch 1 taken 11288 times.
23118 size_t num_commands = script->zasm_script ? script->zasm_script->size : 0;
13761
13762
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputl(num_commands,f))
13763 {
13764 new_return(6);
13765 }
13766
13767 //Metadata
13768 23118 zasm_meta const& tmeta = script->meta;
13769
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.zasm_v,f))
13770 {
13771 new_return(7);
13772 }
13773
13774
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.meta_v,f))
13775 {
13776 new_return(8);
13777 }
13778
13779
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.ffscript_v,f))
13780 {
13781 new_return(9);
13782 }
13783
13784
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_putc((int)tmeta.script_type,f))
13785 {
13786 new_return(10);
13787 }
13788
13789
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(int32_t q = 0; q < 8; ++q)
13790 {
13791
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.run_idens[q],f))
13792 new_return(11);
13793 184944 }
13794
13795
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(int32_t q = 0; q < 8; ++q)
13796 {
13797
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putc(tmeta.run_types[q],f))
13798 {
13799 new_return(12);
13800 }
13801 184944 }
13802
13803
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_putc(tmeta.flags,f))
13804 {
13805 new_return(13);
13806 }
13807
13808
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v1,f))
13809 {
13810 new_return(14);
13811 }
13812
13813
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v2,f))
13814 {
13815 new_return(15);
13816 }
13817
13818
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v3,f))
13819 {
13820 new_return(16);
13821 }
13822
13823
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v4,f))
13824 {
13825 new_return(17);
13826 }
13827
13828
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_putcstr(tmeta.script_name,f))
13829 new_return(18);
13830
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23118 times.
23118 if(!p_putcstr(tmeta.author,f))
13831 new_return(19);
13832
2/2
✓ Branch 0 taken 231180 times.
✓ Branch 1 taken 23118 times.
254298 for(auto q = 0; q < 10; ++q)
13833 {
13834
1/2
✓ Branch 0 taken 231180 times.
✗ Branch 1 not taken.
231180 if(!p_putcstr(tmeta.attributes[q],f))
13835 new_return(27);
13836
1/2
✓ Branch 0 taken 231180 times.
✗ Branch 1 not taken.
231180 if(!p_putwstr(tmeta.attributes_help[q],f))
13837 new_return(28);
13838 231180 }
13839
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13840 {
13841
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.attribytes[q],f))
13842 new_return(29);
13843
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putwstr(tmeta.attribytes_help[q],f))
13844 new_return(30);
13845 184944 }
13846
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13847 {
13848
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.attrishorts[q],f))
13849 new_return(31);
13850
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putwstr(tmeta.attrishorts_help[q],f))
13851 new_return(32);
13852 184944 }
13853
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 23118 times.
393006 for(auto q = 0; q < 16; ++q)
13854 {
13855
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.usrflags[q],f))
13856 new_return(33);
13857
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putwstr(tmeta.usrflags_help[q],f))
13858 new_return(34);
13859 369888 }
13860
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13861 {
13862
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.initd[q],f))
13863 new_return(35);
13864
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putwstr(tmeta.initd_help[q],f))
13865 new_return(36);
13866 184944 }
13867
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13868 {
13869
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putc(tmeta.initd_type[q],f))
13870 new_return(37);
13871 184944 }
13872
13873
2/2
✓ Branch 0 taken 11288 times.
✓ Branch 1 taken 2056888 times.
2068176 for(int32_t j=0; j<num_commands; j++)
13874 {
13875 2056888 auto& zas = script->zasm_script->zasm[j];
13876
1/2
✓ Branch 0 taken 2056888 times.
✗ Branch 1 not taken.
2056888 if(!p_iputw(zas.command,f))
13877 {
13878 new_return(20);
13879 }
13880
13881
2/2
✓ Branch 0 taken 2045058 times.
✓ Branch 1 taken 11830 times.
2056888 if(zas.command==0xFFFF)
13882 {
13883 11830 break;
13884 }
13885 else
13886 {
13887
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg1,f))
13888 {
13889 new_return(21);
13890 }
13891
13892
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg2,f))
13893 {
13894 new_return(22);
13895 }
13896
13897
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg3,f))
13898 {
13899 new_return(23);
13900 }
13901
13902 2045058 uint32_t sz = 0;
13903
2/2
✓ Branch 0 taken 2340 times.
✓ Branch 1 taken 2042718 times.
2045058 if(zas.strptr)
13904 2340 sz = zas.strptr->size();
13905
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(sz,f))
13906 {
13907 new_return(23);
13908 }
13909
2/2
✓ Branch 0 taken 2042718 times.
✓ Branch 1 taken 2340 times.
2045058 if(sz)
13910 {
13911 2340 auto& str = *zas.strptr;
13912
2/2
✓ Branch 0 taken 214720 times.
✓ Branch 1 taken 2340 times.
217060 for(size_t q = 0; q < sz; ++q)
13913 {
13914
1/2
✓ Branch 0 taken 214720 times.
✗ Branch 1 not taken.
214720 if(!p_putc(str[q],f))
13915 {
13916 new_return(24);
13917 }
13918 214720 }
13919 2340 }
13920 2045058 sz = 0;
13921
2/2
✓ Branch 0 taken 2045036 times.
✓ Branch 1 taken 22 times.
2045058 if(zas.vecptr)
13922 22 sz = zas.vecptr->size();
13923
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(sz,f))
13924 {
13925 new_return(25);
13926 }
13927
2/2
✓ Branch 0 taken 2045036 times.
✓ Branch 1 taken 22 times.
2045058 if(sz) //vector found
13928 {
13929 22 auto& vec = *zas.vecptr;
13930
2/2
✓ Branch 0 taken 352 times.
✓ Branch 1 taken 22 times.
374 for(size_t q = 0; q < sz; ++q)
13931 {
13932
1/2
✓ Branch 0 taken 352 times.
✗ Branch 1 not taken.
352 if(!p_iputl(vec[q],f))
13933 {
13934 new_return(26);
13935 }
13936 352 }
13937 22 }
13938 }
13939 2045058 }
13940
13941 23118 new_return(0);
13942 }
13943
13944 extern SAMPLE customsfxdata[WAV_COUNT];
13945 extern uint8_t customsfxflag[WAV_COUNT>>3];
13946
13947 9 int32_t writesfx(PACKFILE *f, zquestheader *Header)
13948 {
13949 //these are here to bypass compiler warnings about unused arguments
13950 9 Header=Header;
13951
13952 9 dword section_id=ID_SFX;
13953 9 dword section_version=V_SFX;
13954 9 dword section_size=0;
13955
13956 //section id
13957
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
13958 {
13959 new_return(1);
13960 }
13961
13962 //section version info
13963
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
13964 {
13965 new_return(2);
13966 }
13967
13968
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
13969 {
13970 new_return(3);
13971 }
13972
13973
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13974 {
13975 18 fake_pack_writing=(writecycle==0);
13976
13977 //section size
13978
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
13979 {
13980 new_return(4);
13981 }
13982
13983 18 writesize=0;
13984
13985
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for(int32_t i=0; i<WAV_COUNT>>3; i++)
13986 {
13987
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_putc(customsfxflag[i],f))
13988 {
13989 new_return(5);
13990 }
13991 576 }
13992
13993
2/2
✓ Branch 0 taken 4590 times.
✓ Branch 1 taken 18 times.
4608 for(int32_t i=1; i<WAV_COUNT; i++)
13994 {
13995
2/2
✓ Branch 0 taken 1260 times.
✓ Branch 1 taken 3330 times.
4590 if(get_bit(customsfxflag, i-1) == 0)
13996 3330 continue;
13997
13998
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!pfwrite(sfx_string[i], 36, f))
13999 {
14000 new_return(5);
14001 }
14002 1260 }
14003
14004
2/2
✓ Branch 0 taken 4590 times.
✓ Branch 1 taken 18 times.
4608 for(int32_t i=1; i<WAV_COUNT; i++)
14005 {
14006
2/2
✓ Branch 0 taken 1260 times.
✓ Branch 1 taken 3330 times.
4590 if(get_bit(customsfxflag, i-1) == 0)
14007 3330 continue;
14008
14009
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].bits,f))
14010 {
14011 new_return(5);
14012 }
14013
14014
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].stereo,f))
14015 {
14016 new_return(6);
14017 }
14018
14019
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].freq,f))
14020 {
14021 new_return(7);
14022 }
14023
14024
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].priority,f))
14025 {
14026 new_return(8);
14027 }
14028
14029
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].len,f))
14030 {
14031 new_return(9);
14032 }
14033
14034
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].loop_start,f))
14035 {
14036 new_return(10);
14037 }
14038
14039
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].loop_end,f))
14040 {
14041 new_return(11);
14042 }
14043
14044
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].param,f))
14045 {
14046 new_return(12);
14047 }
14048
14049 //de-endianfy the data
14050 1260 int32_t wordstowrite = (customsfxdata[i].bits==8?1:2)*(customsfxdata[i].stereo==0?1:2)*customsfxdata[i].len/sizeof(word);
14051
14052
2/2
✓ Branch 0 taken 28596352 times.
✓ Branch 1 taken 1260 times.
28597612 for(int32_t j=0; j<wordstowrite; j++)
14053 {
14054
1/2
✓ Branch 0 taken 28596352 times.
✗ Branch 1 not taken.
28596352 if(!p_iputw(((word *)customsfxdata[i].data)[j],f))
14055 {
14056 new_return(13);
14057 }
14058 28596352 }
14059 1260 }
14060
14061
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14062 {
14063 9 section_size=writesize;
14064 9 }
14065 18 }
14066
14067
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14068 {
14069 char ebuf[80];
14070 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14071 jwin_alert("Error: writesfx()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14072 }
14073
14074 9 new_return(0);
14075 }
14076
14077 9 int32_t writeinitdata(PACKFILE *f, zquestheader *)
14078 {
14079 9 dword section_id=ID_INITDATA;
14080 9 dword section_version=V_INITDATA;
14081 9 dword section_size = 0;
14082
14083 9 zinit.last_map=Map.getCurrMap();
14084 9 zinit.last_screen=Map.getCurrScr();
14085 9 zinit.normalize();
14086
14087 //section id
14088
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14089 {
14090 new_return(1);
14091 }
14092
14093 //section version info
14094
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14095 {
14096 new_return(2);
14097 }
14098
14099
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14100 {
14101 new_return(3);
14102 }
14103
14104 //TODO
14105
14106
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14107 {
14108 18 fake_pack_writing=(writecycle==0);
14109
14110 //section size
14111
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14112 new_return(4);
14113
14114 18 writesize=0;
14115
14116
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for(int q = 0; q < MAXITEMS/8; ++q)
14117
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_putc(zinit.items[q], f))
14118 new_return(5);
14119
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int q = 0; q < MAXLEVELS; ++q)
14120 {
14121
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(zinit.litems[q], f))
14122 new_return(6);
14123 9216 }
14124
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbvec(zinit.level_keys, f))
14125 new_return(10);
14126
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(MAX_COUNTERS,f))
14127 new_return(11);
14128
2/2
✓ Branch 0 taken 1926 times.
✓ Branch 1 taken 18 times.
1944 for(int q = 0; q < MAX_COUNTERS; ++q)
14129
1/2
✓ Branch 0 taken 1926 times.
✗ Branch 1 not taken.
1926 if(!p_iputw(zinit.counter[q],f))
14130 new_return(12);
14131
2/2
✓ Branch 0 taken 1926 times.
✓ Branch 1 taken 18 times.
1944 for(int q = 0; q < MAX_COUNTERS; ++q)
14132
1/2
✓ Branch 0 taken 1926 times.
✗ Branch 1 not taken.
1926 if(!p_iputw(zinit.mcounter[q],f))
14133 new_return(13);
14134
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.bomb_ratio,f))
14135 new_return(14);
14136
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hcp,f))
14137 new_return(15);
14138
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hcp_per_hc,f))
14139 new_return(16);
14140
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.cont_heart,f))
14141 new_return(17);
14142
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hp_per_heart,f))
14143 new_return(18);
14144
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.magic_per_block,f))
14145 new_return(19);
14146
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_damage_multiplier,f))
14147 new_return(20);
14148
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.ene_damage_multiplier,f))
14149 new_return(21);
14150
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_type,f))
14151 new_return(22);
14152
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_arg,f))
14153 new_return(23);
14154
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_percent,f))
14155 new_return(24);
14156
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.def_lightrad,f))
14157 new_return(25);
14158
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.transdark_percent,f))
14159 new_return(26);
14160
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.darkcol,f))
14161 new_return(27);
14162
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_x,f))
14163 new_return(28);
14164
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_y,f))
14165 new_return(29);
14166
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_xofs,f))
14167 new_return(30);
14168
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_yofs,f))
14169 new_return(31);
14170
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_color,f))
14171 new_return(32);
14172
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_bbox_1_color,f))
14173 new_return(33);
14174
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_bbox_2_color,f))
14175 new_return(34);
14176
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_flags,f))
14177 new_return(35);
14178
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbitstr(zinit.flags,f))
14179 new_return(36);
14180
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.last_map,f))
14181 new_return(37);
14182
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.last_screen,f))
14183 new_return(38);
14184
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_x,f))
14185 new_return(39);
14186
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_y,f))
14187 new_return(40);
14188
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_is_offset,f))
14189 new_return(41);
14190
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_speed,f))
14191 new_return(42);
14192
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.gravity,f))
14193 new_return(43);
14194
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.swimgravity,f))
14195 new_return(44);
14196
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.terminalv,f))
14197 new_return(45);
14198
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_speed,f))
14199 new_return(46);
14200
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_mult,f))
14201 new_return(47);
14202
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_div,f))
14203 new_return(48);
14204
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimUpStep,f))
14205 new_return(49);
14206
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimSideStep,f))
14207 new_return(50);
14208
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimDownStep,f))
14209 new_return(51);
14210
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.exitWaterJump,f))
14211 new_return(52);
14212
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroStep,f))
14213 new_return(53);
14214
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.heroAnimationStyle,f))
14215 new_return(54);
14216
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.jump_hero_layer_threshold,f))
14217 new_return(55);
14218
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.bunny_ltm,f))
14219 new_return(56);
14220
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.start_dmap,f))
14221 new_return(57);
14222
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.subscrSpeed,f))
14223 new_return(58);
14224
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.switchhookstyle,f))
14225 new_return(59);
14226
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.magicdrainrate,f))
14227 new_return(60);
14228
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputzf(zinit.shove_offset,f))
14229 new_return(61);
14230
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbitstr(zinit.gen_doscript, f))
14231 new_return(62);
14232
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_exitState, f))
14233 new_return(63);
14234
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_reloadState, f))
14235 new_return(64);
14236
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_initd, f))
14237 new_return(65);
14238
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_eventstate, f))
14239 new_return(66);
14240
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_data, f))
14241 new_return(67);
14242
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.screen_data, f))
14243 new_return(68);
14244
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickerspeed, f))
14245 new_return(69);
14246
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickercolor, f))
14247 new_return(70);
14248
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickertransp, f))
14249 new_return(71);
14250
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputzf(zinit.air_drag, f))
14251 new_return(72);
14252
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.light_wave_rate, f))
14253 new_return(73);
14254
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.light_wave_size, f))
14255 new_return(74);
14256
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.region_mapping, f))
14257 new_return(75);
14258
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(uint q = 0; q < NUM_BOTTLE_SLOTS; ++q)
14259
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if (!p_putc(zinit.bottle_slot[q], f))
14260 new_return(76);
14261
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putbvec(zinit.lvlswitches, f))
14262 new_return(77);
14263
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.item_spawn_flicker, f))
14264 new_return(78);
14265
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.item_timeout_dur, f))
14266 new_return(79);
14267
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.item_timeout_flicker, f))
14268 new_return(80);
14269
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.item_flicker_speed, f))
14270 new_return(81);
14271
2/2
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 18 times.
108 for(int q = 0; q < SPRITE_THRESHOLD_MAX; ++q)
14272
1/2
✓ Branch 0 taken 90 times.
✗ Branch 1 not taken.
90 if (!p_iputw(zinit.sprite_z_thresholds[q], f))
14273 new_return(82);
14274
14275
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14276 {
14277 9 section_size=writesize;
14278 9 }
14279 18 }
14280
14281
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14282 {
14283 char ebuf[80];
14284 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14285 jwin_alert("Error: writeinitdata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14286 }
14287
14288 9 new_return(0);
14289 }
14290
14291 9 int32_t writeitemdropsets(PACKFILE *f, zquestheader *Header)
14292 {
14293 //these are here to bypass compiler warnings about unused arguments
14294 9 Header=Header;
14295
14296 9 dword section_id=ID_ITEMDROPSETS;
14297 9 dword section_version=V_ITEMDROPSETS;
14298 // dword section_size=0;
14299 9 dword section_size = 0;
14300 9 word num_item_drop_sets=count_item_drop_sets();
14301
14302 //section id
14303
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14304 {
14305 new_return(1);
14306 }
14307
14308 //section version info
14309
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14310 {
14311 new_return(2);
14312 }
14313
14314
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14315 {
14316 new_return(3);
14317 }
14318
14319
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14320 {
14321 18 fake_pack_writing=(writecycle==0);
14322
14323 //section size
14324
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14325 {
14326 new_return(4);
14327 }
14328
14329 18 writesize=0;
14330
14331 //finally... section data
14332
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(num_item_drop_sets,f))
14333 {
14334 new_return(5);
14335 }
14336
14337
2/2
✓ Branch 0 taken 236 times.
✓ Branch 1 taken 18 times.
254 for(int32_t i=0; i<num_item_drop_sets; i++)
14338 {
14339
1/2
✓ Branch 0 taken 236 times.
✗ Branch 1 not taken.
236 if(!pfwrite(item_drop_sets[i].name, sizeof(item_drop_sets[i].name)-1, f))
14340 {
14341 new_return(6);
14342 }
14343
14344
2/2
✓ Branch 0 taken 2360 times.
✓ Branch 1 taken 236 times.
2596 for(int32_t j=0; j<10; ++j)
14345 {
14346
1/2
✓ Branch 0 taken 2360 times.
✗ Branch 1 not taken.
2360 if(!p_iputw(item_drop_sets[i].item[j],f))
14347 {
14348 new_return(7);
14349 }
14350 2360 }
14351
14352
2/2
✓ Branch 0 taken 2596 times.
✓ Branch 1 taken 236 times.
2832 for(int32_t j=0; j<11; ++j)
14353 {
14354
1/2
✓ Branch 0 taken 2596 times.
✗ Branch 1 not taken.
2596 if(!p_iputw(item_drop_sets[i].chance[j],f))
14355 {
14356 new_return(8);
14357 }
14358 2596 }
14359 236 }
14360
14361
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14362 {
14363 9 section_size=writesize;
14364 9 }
14365 18 }
14366
14367
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14368 {
14369 char ebuf[80];
14370 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14371 jwin_alert("Error: writeitemdropsets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14372 }
14373
14374 9 new_return(0);
14375 }
14376
14377 9 int32_t writefavorites(PACKFILE *f, zquestheader*)
14378 {
14379 9 dword section_id=ID_FAVORITES;
14380 9 dword section_version=V_FAVORITES;
14381 9 dword section_size = 0;
14382
14383 //section id
14384
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14385 {
14386 new_return(1);
14387 }
14388
14389 //section version info
14390
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14391 {
14392 new_return(2);
14393 }
14394
14395
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14396 {
14397 new_return(3);
14398 }
14399
14400
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14401 {
14402 18 fake_pack_writing=(writecycle==0);
14403
14404 //section size
14405
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14406 new_return(4);
14407
14408 18 writesize=0;
14409
14410
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(FAVORITECOMBO_PER_ROW,f))
14411 new_return(16);
14412
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(FAVORITECOMBO_PER_PAGE,f)) // Just in case pages get resized again
14413 new_return(17);
14414
14415 18 word favcmb_cnt = 0;
14416
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 22234 times.
22238 for(int q = MAXFAVORITECOMBOS-1; q >= 0; --q)
14417
2/2
✓ Branch 0 taken 22220 times.
✓ Branch 1 taken 14 times.
22234 if(favorite_combos[q] != -1)
14418 {
14419 14 favcmb_cnt = q+1;
14420 14 break;
14421 }
14422
14423
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(favcmb_cnt,f)) // This'll probably never change, huh?
14424 new_return(5);
14425
14426
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 18 times.
478 for(int i=0; i<favcmb_cnt; ++i)
14427 {
14428
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_putc(favorite_combo_modes[i], f))
14429 new_return(6);
14430
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_iputl(favorite_combos[i], f))
14431 new_return(7);
14432 460 }
14433
14434
14435 18 word max_combo_cols = MAX_COMBO_COLS;
14436
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(max_combo_cols,f))
14437 new_return(9);
14438
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int q = 0; q < max_combo_cols; ++q)
14439 {
14440
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(First[q],f))
14441 new_return(10);
14442
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(combo_alistpos[q],f))
14443 new_return(11);
14444
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(combo_pool_listpos[q],f))
14445 new_return(12);
14446 72 }
14447 18 word max_mappages = MAX_MAPPAGE_BTNS;
14448
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(max_mappages,f))
14449 new_return(13);
14450
2/2
✓ Branch 0 taken 162 times.
✓ Branch 1 taken 18 times.
180 for(int q = 0; q < max_mappages; ++q)
14451 {
14452
1/2
✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
162 if(!p_iputl(map_page[q].map,f))
14453 new_return(14);
14454
1/2
✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
162 if(!p_iputl(map_page[q].screen,f))
14455 new_return(15);
14456 162 }
14457
14458
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14459 {
14460 9 section_size=writesize;
14461 9 }
14462 18 }
14463
14464
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14465 {
14466 char ebuf[80];
14467 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14468 jwin_alert("Error: writefavorites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14469 }
14470
14471 9 new_return(0);
14472 }
14473
14474 9 static int32_t _save_unencoded_quest_int(const char *filename, bool compressed, const char *afname)
14475 {
14476
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!afname) afname = filename;
14477 9 reset_combo_animations();
14478 9 reset_combo_animations2();
14479 9 strcpy(header.id_str,QH_NEWIDSTR);
14480 9 header.zelda_version = ZELDA_VERSION;
14481 9 header.internal = INTERNAL_VERSION;
14482 9 header.data_flags[ZQ_TILES] = true;
14483 9 header.data_flags[ZQ_CHEATS2] = 1;
14484 9 header.build=VERSION_BUILD;
14485
14486
2/2
✓ Branch 0 taken 2268 times.
✓ Branch 1 taken 9 times.
2277 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
14487 {
14488 2268 set_bit(midi_flags,i,int32_t(customtunes[i].data!=NULL));
14489 2268 }
14490
14491 char zinfofilename[2048];
14492 9 replace_extension(zinfofilename, afname, "zinfo", 2047);
14493
14494 9 box_start(1, "Saving Quest", get_zc_font(font_lfont), font, true);
14495 9 box_out("Saving Quest...");
14496 9 box_eol();
14497 9 box_eol();
14498
14499
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 std::string tmp_filename = util::create_temp_file_path(filename);
14500
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 PACKFILE *f = pack_fopen_password(tmp_filename.c_str(),compressed?F_WRITE_PACKED:F_WRITE, "");
14501
14502
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!f)
14503 return 1;
14504
14505
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Header...");
14506
14507
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeheader(f,&header)!=0)
14508 return 2;
14509
14510
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14511
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14512
14513
14514
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(header.external_zinfo)
14515 {
14516 PACKFILE *inf = pack_fopen_password(zinfofilename, F_WRITE, "");
14517
14518 box_out("Writing ZInfo...");
14519 if(inf)
14520 {
14521 if(writezinfo(inf,ZI)!=0)
14522 return 2;
14523
14524 pack_fclose(inf);
14525 box_out("okay.");
14526 }
14527 else box_out(" ...file failure");
14528 box_eol();
14529 }
14530 else
14531 {
14532
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing ZInfo...");
14533
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writezinfo(f,ZI)!=0)
14534 return 2;
14535
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14536
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14537 }
14538
14539
14540
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Rules...");
14541
14542
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writerules(f,&header)!=0)
14543 return 3;
14544
14545
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14546
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14547
14548
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Strings...");
14549
14550
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)!=0)
14551 return 4;
14552
14553
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14554
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14555
14556
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Doors...");
14557
14558
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writedoorcombosets(f,&header)!=0)
14559 return 5;
14560
14561
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14562
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14563
14564
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing DMaps...");
14565
14566
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writedmaps(f,header.zelda_version,header.build,0,MAXDMAPS)!=0)
14567 return 6;
14568
14569
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14570
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14571
14572
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing &QMisc. Data...");
14573
14574
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writemisc(f,&header)!=0)
14575 return 7;
14576
14577
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14578
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14579
14580
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing &QMisc. Colors...");
14581
14582
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writemisccolors(f,&header)!=0)
14583 return 8;
14584
14585
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14586
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14587
14588
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Game Icons...");
14589
14590
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writegameicons(f,&header)!=0)
14591 return 9;
14592
14593
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14594
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14595
14596
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Items...");
14597
14598
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeitems(f,&header)!=0)
14599 return 10;
14600
14601
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14602
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14603
14604
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Weapons...");
14605
14606
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeweapons(f,&header)!=0)
14607 return 11;
14608
14609
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14610
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14611
14612
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Maps...");
14613
14614
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writemaps(f,&header)!=0)
14615 return 12;
14616
14617
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14618
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14619
14620
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Combos...");
14621
14622
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writecombos(f,header.zelda_version,header.build,0,MAXCOMBOS)!=0)
14623 return 13;
14624
14625
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14626
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14627
14628
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Combo Aliases...");
14629
14630
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writecomboaliases(f,header.zelda_version,header.build)!=0)
14631 return 14;
14632
14633
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14634
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14635
14636
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Color Data...");
14637
14638
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writecolordata(f,header.zelda_version,header.build,0,newerpdTOTAL)!=0)
14639 return 15;
14640
14641
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14642
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14643
14644
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Tiles...");
14645
14646
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writetiles(f,header.zelda_version,header.build,0,NEWMAXTILES)!=0)
14647 return 16;
14648
14649
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14650
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14651
14652
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing MIDIs...");
14653
14654
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writemidis(f)!=0)
14655 return 17;
14656
14657
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14658
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14659
14660
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Cheat Codes...");
14661
14662
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writecheats(f,&header)!=0)
14663 return 18;
14664
14665
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14666
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14667
14668
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Init. Data...");
14669
14670
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeinitdata(f,&header)!=0)
14671 return 19;
14672
14673
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14674
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14675
14676
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Guy Data...");
14677
14678
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeguys(f,&header)!=0)
14679 return 20;
14680
14681
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14682
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14683
14684
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Hero Sprite Data...");
14685
14686
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeherosprites(f,&header)!=0)
14687 return 21;
14688
14689
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14690
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14691
14692
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Subscreen Data...");
14693
14694
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writesubscreens(f,&header)!=0)
14695 return 22;
14696
14697
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14698
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14699
14700
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing FF Script Data...");
14701
14702
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeffscript(f,&header)!=0)
14703 return 23;
14704
14705
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14706
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14707
14708
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing SFX Data...");
14709
14710
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writesfx(f,&header)!=0)
14711 return 24;
14712
14713
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14714
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14715
14716
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Item Drop Sets...");
14717
14718
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeitemdropsets(f, &header)!=0)
14719 return 25;
14720
14721
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14722
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14723
14724
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Favorite Combos...");
14725
14726
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writefavorites(f, &header)!=0)
14727 return 26;
14728
14729
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14730
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14731
14732
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 pack_fclose(f);
14733
14734
14735
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
9 if(header.use_keyfile&&header.dirty_password)
14736 {
14737 char const* kfname = filename;
14738 char keyfilename[2048]={0};
14739 zprint2("Writing key files for '%s'\n", kfname);
14740
14741 char temp_pw[QSTPWD_LEN] = {0};
14742 uint ind = 0;
14743 for(char const* ext : {"key","zpwd","zcheat"})
14744 {
14745 replace_extension(keyfilename, kfname, ext, 2047);
14746 PACKFILE *fp = pack_fopen_password(keyfilename, F_WRITE, "");
14747 char msg[80] = {0};
14748 sprintf(msg, "ZQuest Auto-Generated Quest Password Key File. DO NOT EDIT!");
14749 msg[78]=13;
14750 msg[79]=10;
14751 pfwrite(msg, 80, fp);
14752 p_iputw(header.zelda_version,fp);
14753 p_putc(header.build,fp);
14754 char const* pwd = header.password;
14755 if(ind == 2) //.zcheat, hashed pwd
14756 {
14757 char hashmap = 'Z';
14758 hashmap += 'Q';
14759 hashmap += 'U';
14760 hashmap += 'E';
14761 hashmap += 'S';
14762 hashmap += 'T';
14763 for ( int q = 0; q < QSTPWD_LEN; ++q )
14764 {
14765 temp_pw[q] = header.password[q];
14766 temp_pw[q] += hashmap;
14767 }
14768 pwd = temp_pw;
14769 }
14770 pfwrite(pwd, strlen(pwd), fp);
14771 pack_fclose(fp);
14772 ++ind;
14773 }
14774 }
14775
14776 // Move file to destination at end, to avoid issues with file being unavailable to test mode.
14777 9 std::error_code ec;
14778
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 fs::rename(tmp_filename, filename, ec);
14779
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (ec)
14780 {
14781 al_trace("Error saving: %s\n", std::strerror(ec.value()));
14782 return ec.value();
14783 }
14784
14785
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 strncpy(header.zelda_version_string, getVersionString(), sizeof(header.zelda_version_string));
14786
14787 #ifdef __EMSCRIPTEN__
14788 em_sync_fs();
14789 #endif
14790
14791 9 return 0;
14792 9 }
14793
14794 // #ifdef _WIN32
14795 // static std::time_t to_time_t(FILETIME const& ft) {
14796 // uint64_t t = (static_cast<uint64_t>(ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
14797 // t -= 116444736000000000ull;
14798 // t /= 10000000u;
14799 // return static_cast<std::time_t>(t);
14800 // }
14801 // #else
14802 // #endif
14803 template<typename TP>
14804 6 static std::time_t to_time_t(TP tp) {
14805 using namespace std::chrono;
14806 6 auto sctp = time_point_cast<system_clock::duration>(tp - TP::clock::now() + system_clock::now());
14807 6 return system_clock::to_time_t(sctp);
14808 }
14809
14810 6 std::string get_time_last_modified_string(std::string path)
14811 {
14812
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 auto write_time = fs::last_write_time(path);
14813 // TODO: C++20 but not supported yet.
14814 // auto tt = std::chrono::clock_cast<std::chrono::system_clock>(write_time);
14815 6 std::time_t tt = to_time_t(write_time);
14816 6 std::tm *gmt = std::gmtime(&tt);
14817 6 std::stringstream buffer;
14818
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 buffer << std::put_time(gmt, "%Y-%m-%d");
14819
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 std::string formattedFileTime = buffer.str();
14820 6 return formattedFileTime;
14821
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 }
14822
14823 9 int32_t save_unencoded_quest(const char *filename, bool compressed, const char *afname)
14824 {
14825 // Always backup quest if it was last saved in a different version of the editor,
14826 // or if this a new file and is overwritting another qst file.
14827
10/16
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 6 times.
✓ Branch 8 taken 3 times.
✓ Branch 9 taken 6 times.
✓ Branch 10 taken 3 times.
✓ Branch 11 taken 6 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
9 if (exists(filename) && std::string(getVersionString()) != header.zelda_version_string)
14828 {
14829 6 std::string backup_name;
14830
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 std::string last_mod = get_time_last_modified_string(filename);
14831
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (strlen(header.zelda_version_string) > 0)
14832 {
14833
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 backup_name = fmt::format("{}-v{}", last_mod, header.zelda_version_string);
14834 6 }
14835 else
14836 {
14837 backup_name = fmt::format("{}", last_mod);
14838 }
14839
7/14
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 6 times.
✗ Branch 13 not taken.
6 std::string backup_fname = fmt::format("{}-{}{}", fs::path(filename).stem().string(), backup_name, fs::path(filename).extension().string());
14840
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 fs::path backup_path = fs::path("backups") / backup_fname;
14841
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if (!fs::exists(backup_path))
14842 {
14843
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 fs::create_directories(fs::path("backups"));
14844
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 if (fs::copy_file(filename, backup_path))
14845 {
14846
5/10
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 6 times.
6 InfoDialog("Quest Backup", fmt::format("A backup has been saved to {}", backup_path.string())).show();
14847 6 }
14848 else
14849 {
14850 InfoDialog("Quest Backup", fmt::format("Failed to save backup at {}", backup_path.string())).show();
14851 }
14852 6 }
14853 6 }
14854
14855 9 auto ret = _save_unencoded_quest_int(filename,compressed,afname);
14856 9 fake_pack_writing = false;
14857
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(ret)
14858 {
14859 box_out("-- Error saving quest file! --");
14860 box_end(true);
14861 }
14862 9 else box_end(false);
14863 9 return ret;
14864 }
14865
14866 9 int32_t save_quest(const char *filename, bool timed_save)
14867 {
14868
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 int32_t retention=timed_save?AutoSaveRetention:AutoBackupRetention;
14869
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 bool compress=!(timed_save&&UncompressedAutoSaves);
14870 char ext1[5];
14871 9 ext1[0]=0;
14872
14873
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(timed_save)
14874 {
14875 sprintf(ext1, "qt");
14876 }
14877 else
14878 {
14879 9 sprintf(ext1, "qb");
14880 }
14881
14882
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(retention)
14883 {
14884 char backupname[2048];
14885 char backupname2[2048];
14886 char ext[12];
14887
14888 for(int32_t i=retention-1; i>0; --i)
14889 {
14890 sprintf(ext, "%s%d", ext1, i-1);
14891 replace_extension(backupname, filepath, ext, 2047);
14892
14893 if(exists(backupname))
14894 {
14895 sprintf(ext, "%s%d", ext1, i);
14896 replace_extension(backupname2, filepath, ext, 2047);
14897
14898 if(exists(backupname2))
14899 {
14900 remove(backupname2);
14901 }
14902
14903 rename(backupname, backupname2);
14904 }
14905 }
14906
14907 //don't do this if we're not saving to the same name -DD
14908 if(!timed_save && !strcmp(filepath, filename))
14909 {
14910 sprintf(ext, "%s%d", ext1, 0);
14911 replace_extension(backupname, filepath, ext, 2047);
14912 rename(filepath, backupname);
14913 }
14914 }
14915
14916 int32_t ret;
14917 9 ret = save_unencoded_quest(filename, compress, filename);
14918
14919 9 return ret;
14920 }
14921
14922 1 void center_zq_class_dialogs()
14923 {
14924 1 jwin_center_dialog(pwd_dlg);
14925 1 }
14926
14927 void zmap::prv_secrets(bool high16only)
14928 {
14929 mapscr *s = &prvscr;
14930 mapscr *t = prvlayers;
14931 int32_t ft=0;
14932
14933 for(int32_t i=0; i<176; i++)
14934 {
14935 if(!high16only)
14936 {
14937 for(int32_t j=-1; j<6; j++)
14938 {
14939 int32_t newflag = -1;
14940
14941 for(int32_t iter=0; iter<2; ++iter)
14942 {
14943 if(!t[j].valid)
14944 continue;
14945
14946 int32_t checkflag=combobuf[t[j].data[i]].flag;
14947
14948 if(iter==1)
14949 {
14950 checkflag=t[j].sflag[i];
14951 }
14952
14953 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
14954 if (ft != -1)
14955 {
14956 if(j==-1)
14957 {
14958 s->data[i] = s->secretcombo[ft];
14959 s->cset[i] = s->secretcset[ft];
14960 newflag = s->secretflag[ft];
14961 }
14962 else
14963 {
14964 t[j].data[i] = t[j].secretcombo[ft];
14965 t[j].cset[i] = t[j].secretcset[ft];
14966 newflag = t[j].secretflag[ft];
14967 }
14968 }
14969 }
14970
14971 if(newflag >-1)
14972 {
14973 ((j==-1) ? s->sflag[i] : t[j].sflag[i]) = newflag;
14974 }
14975 }
14976 }
14977
14978 //if(true)
14979 //{
14980 int32_t newflag = -1;
14981
14982 for(int32_t iter=0; iter<2; ++iter)
14983 {
14984 int32_t checkflag=combobuf[s->data[i]].flag;
14985
14986 if(iter==1)
14987 {
14988 checkflag=s->sflag[i];
14989 }
14990
14991 if((checkflag > 15)&&(checkflag < 32))
14992 {
14993 s->data[i] = s->secretcombo[(checkflag)-16+4];
14994 s->cset[i] = s->secretcset[(checkflag)-16+4];
14995 newflag = s->secretflag[(checkflag)-16+4];
14996 // putit = true;
14997 }
14998 }
14999
15000 if(newflag >-1) s->sflag[i] = newflag;
15001
15002 for(int32_t j=0; j<6; j++)
15003 {
15004 if(!t[j].valid) continue;
15005
15006 int32_t newflag2 = -1;
15007
15008 for(int32_t iter=0; iter<2; ++iter)
15009 {
15010 int32_t checkflag=combobuf[t[j].data[i]].flag;
15011
15012 if(iter==1)
15013 {
15014 checkflag=t[j].sflag[i];
15015 }
15016
15017 if((checkflag > 15)&&(checkflag < 32))
15018 {
15019 t[j].data[i] = t[j].secretcombo[(checkflag)-16+4];
15020 t[j].cset[i] = t[j].secretcset[(checkflag)-16+4];
15021 newflag2 = t[j].secretflag[(checkflag)-16+4];
15022 }
15023 }
15024
15025 if(newflag2 >-1) t[j].sflag[i] = newflag2;
15026 }
15027 }
15028
15029 //FFCs
15030 word num_ffcs = s->numFFC();
15031 for(word i=0; i<num_ffcs; ++i)
15032 {
15033 if(!high16only)
15034 {
15035 for(int32_t iter=0; iter<1; ++iter)
15036 {
15037 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
15038
15039 if(iter==1)
15040 {
15041 checkflag=s->sflag[i];
15042 }
15043
15044 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
15045 if (ft != -1)
15046 {
15047 s->ffcs[i].data = s->secretcombo[ft];
15048 s->ffcs[i].cset = s->secretcset[ft];
15049 }
15050 }
15051 }
15052
15053 if(!(s->flags2&fCLEARSECRET) || high16only || s->flags4&fENEMYSCRTPERM)
15054 {
15055 for(int32_t iter=0; iter<1; ++iter)
15056 {
15057 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
15058
15059 if(iter==1)
15060 {
15061 // FFCs can't have flags! Yet...
15062 }
15063
15064 if((checkflag > 15)&&(checkflag < 32))
15065 {
15066 s->ffcs[i].data = s->secretcombo[checkflag - 16 + 4];
15067 s->ffcs[i].cset = s->secretcset[checkflag-16+4];
15068 }
15069 }
15070 }
15071 }
15072 }
15073